gpt4 book ai didi

ios - 离开屏幕时表格单元格的行为极其奇怪

转载 作者:行者123 更新时间:2023-11-29 01:21:19 25 4
gpt4 key购买 nike

这是非常奇怪的行为。当 TableView 第一次加载时,它看起来像这样:

enter image description here

现在,当我向下滚动然后向上滚动时,按钮会出现在以前没有按钮的单元格上!像这样:

enter image description here

我知道这与“这是 UITableView 的预期行为。UITableView 的全部要点是将需要的单元格排队并释放管理内存不需要的单元格”,如此处所述帖子:UITableView in Swift: Offscreen cells are not pre-loaded .

这是我的代码:

var messages = [String]()

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! CathyTaskLogTableViewCell

if messages[indexPath.row] != "" {
cell.messageButton.hidden = false
}

return cell
}

有人能解决这个问题吗?

最佳答案

得到这个结果的原因是 UITableViewCell 被重用了。

if messages[indexPath.row] != "" {
cell.messageButton.hidden = false
}
else
{
cell.messageButton.hidden = true
}

关于ios - 离开屏幕时表格单元格的行为极其奇怪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34563430/

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