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