我想隐藏/取消隐藏 UITableViewCell
中的 UIView
,但很多时候它会为错误的 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
}
关于ios - UITableViewCell 没有正确隐藏 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31767500/