2016-08-16 1 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

관련 문제