0

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

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)
    }

但不知何故,它没有在按钮单击时显示青色。任何人都可以在swift中发布适当的解决方案吗?

4

1 回答 1

0

另一种方法是bool在按钮是否被按下时保留 a 。

然后,在您的:

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

参考

方法,根据该bool值更改背景颜色。选择按钮后,只需翻转bool并调用:

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

参考

于 2016-08-16T16:01:27.223 回答