2016-08-16 6 views
0

私はUITableViewと "A"と呼ばれるボタンを持つUIViewControllerを持っています。このテーブルにはセクションと行があります。今私のシナリオでは、「A」がクリックされたときにセクションをハイライトしたいと思っています。私はviewForHeaderInSectionでこの作業をしたくないので、テーブルビュー全体をリロードする必要はありません。ボタンをクリックしたときのコードは次のとおりです。UITableView全体を更新せずにセクションの背景色を更新

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

ボタンのクリックで何とかシアン色が表示されません。誰でも迅速に適切なソリューションを投稿できますか?

答えて

0

ボタンを押した場合は、boolのままにしておきます。あなたの中に続いて

、:

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

ref

方法は、そのbool値に基づいて背景色を変更します。ボタンが選択され、簡単なフリップboolおよびコール:返事のための

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

ref

+0

感謝を。それが私の問題を解決した – neena

関連する問題