我想隐藏/显示的UIView
在UITableViewCell
,但很多时候它不隐藏它的错误UITableViewCell
。有什么建议?
cellForRowAtIndexPath函数
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;
}
绝对不是使用标签而不是将UITableViewCell子类化并使用IBOutlets的最佳解决方案。
如果您要继承UITableViewCell的子类,则可以覆盖prepareForReuse()
该hidden
属性并将其重置为true
func prepareForReuse()
{
self.HiddenGemView?.hidden = true
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句