gpt4 book ai didi

swift - 更新部分背景颜色而不刷新整个 UITableView

转载 作者:行者123 更新时间:2023-11-30 13:08:49 25 4
gpt4 key购买 nike

我有一个 UIViewController,它有一个 UITableView 和一个名为“A”的按钮。该表有部分和行。现在,在我的场景中,我想在单击“A”时突出显示一个部分。我不想在 viewForHeaderInSection 中完成这项工作,因为我不想重新加载整个 TableView 。我目前在单击按钮时尝试的代码如下,

public func scrollToSection(sectionNumber:Int)
{
let indexPath = NSIndexPath(forRow: 0, inSection: sectionNumber)
let headerView = tableView.headerViewForSection(indexPath.section)
tableView.beginUpdates()
headerView?.contentView.backgroundColor = UIColor.cyanColor()
tableView.endUpdates()
tableView.scrollToRowAtIndexPath(indexPath, atScrollPosition: UITableViewScrollPosition.Middle, animated: true)
}

但不知何故,单击按钮时它没有显示青色。任何人都可以快速发布正确的解决方案吗?

最佳答案

另一种方法是保留一个 bool 按钮是否被按下。

然后,在您的:

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?

ref

方法,根据该 bool 值更改背景颜色。当按钮被选择时,简单地翻转 bool 并调用:

func reloadSections(_ sections: NSIndexSet, withRowAnimation animation: UITableViewRowAnimation)

ref

关于swift - 更新部分背景颜色而不刷新整个 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38979200/

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