gpt4 book ai didi

ios - UITableViewCell 没有正确隐藏 UIView

转载 作者:行者123 更新时间:2023-11-28 07:02:11 25 4
gpt4 key购买 nike

我想隐藏/取消隐藏 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com