ViewController에서 tableView를 설정했습니다. 이 테이블 뷰에는 1 섹션, 2 프로토 타입 셀이 있습니다. 하나는 섹션의 행 수를 반환하는 데 사용되고 다른 하나는 사용자 지정 헤더를 표시하는 데 사용됩니다. 헤더의 레이블에로드하려는 데이터는 행이 선택 될 때마다 생성됩니다. 문제는 ViewController가 처음로드 될 때마다 행이 선택 될 때마다 데이터가 헤더의 레이블에서 업데이트되지 않는다는 것입니다. 뒤로 단추를 누르고 머리글을 포함하는 ViewController로 돌아 가면 머리글에 첨부 된 레이블로 데이터가 업데이트됩니다. 내가 뭘 잘못하고 있니?tableView 헤더가 데이터를 업데이트하지 않습니다. Swift
셀 didSelectRowAtIndexPath 방법에서 사용자 탭이 호출 될 때마다func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return frequency.count
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerCell = tableView.dequeueReusableCellWithIdentifier("customheader") as! CustomHeader
headerCell.dateHeaderlabel.text = StructS.headerDate
headerCell.hourHeaderlabel.text = StructS.headerHours + "-"
headerCell.totalHoursHeaderlabel.text = String(StructS.numberHours)
headerCell.priceHeaderlabel.text = String(StructS.price)
headerCell.backgroundColor = UIColor(red:72/255,green:141/255,blue:200/255,alpha:0.9)
tableView.reloadSections(NSIndexSet(index: 0), withRowAnimation: .None)
return headerCell
}
func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 70.0
}
데이터를 업데이트 한 후 테이블 뷰를 다시로드해야합니다. –
@UmairAfzal 만약'self.tableView.reloadSections (NSIndexSet (index : 0), withRowAnimation : .None)'하면 '또 다른 오류 :'예상 선언문'이 생깁니다. – bibscy
@bogdanbarbulescu 코드 –