我有一个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中发布一个合适的解决方案吗?