I want to hide/unhide an UIView
in the UITableViewCell
, but many times it unhides it for the wrong UITableViewCell
. Any suggestions?
cellForRowAtIndexPath function
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("locationCell", forIndexPath: indexPath) as? UITableViewCell
var viewWithImage = cell?.viewWithTag(22) as UIView!
var cellHiddenGemView = viewWithImage?.viewWithTag(23) as UIView!
var locationObject : PFObject = locationObjects[indexPath.row] as! PFObject
var isSecret = locationObject["isSecret"] as! Bool
cellHiddenGemView?.hidden = true;
if isSecret == true
{
cellHiddenGemView?.hidden = false;
//this view is unhides for the wrong indexes also
}
return cell;
}
Its definitely not the best solution to use tags instead of subclassing UITableViewCell and use IBOutlets.
If you would subclass UITableViewCell you could override prepareForReuse()
and reset the hidden
property to true
func prepareForReuse()
{
self.HiddenGemView?.hidden = true
}
Try defining else
block too. Once this worked for me.
if isSecret == true
{
cellHiddenGemView?.hidden = false;
}
else
{
cellHiddenGemView?.hidden = true;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.