I have custom header views made using UITableViewCell nib. Each of the custom header has buttons and pictures that need to be update based on different actions that user can take with buttons in the header.
I'm having difficult getting reference to the headerView to update its UI.
I obviously cannot use tableView.cellForRowAtIndexPath as it is a header not a tableview cell. I cannot use tableview.headerViewForSection since it was made with a UITableViewCell not a UITableViewHeaderFooterView.
I've also tried using
tableView.reloadSections(indexSet, withRowAnimation: UITableViewRowAnimation.None)
but this yields unwanted stuttering/glitchy UI reload animations even when set to UITableViewRowAnimation.None. The glitch appears to be the header disappearing and then reappearing from the top and the footer view slide down from the top also.
also have tried
tableView.beginUpdates()
tableView.endUpdates()
This has same glitchy effect.
and
let header = tableView.headerViewForSection(button.tag)
//codes to update headerview here
header?.setNeedsDisplay()
header?.setNeedsLayout()
This has no effects.
Any help would be greatly appreciated!
My codes look like this:
Register Nib:
let stickyHeaderNib = UINib(nibName: "Moment_StickyHeaderCell", bundle: nil)
tableView.registerNib(stickyHeaderNib, forCellReuseIdentifier: "moment_stickyHeaderCell")
Then:
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let momentHeader = tableView.dequeueReusableCellWithIdentifier("moment_stickyHeaderCell") as! Moment_StickyHeaderCell
//various buttons and objects here
momentHeader.followButton.addTarget(self, action: "followButtonPressed:", forControlEvents: UIControlEvents.TouchDragInside)
return momentHeader}
Then selector for button:
func followButtonPressed (button: UIButton) {
let moment = moments[button.tag]
let point = tableView.convertPoint(CGPointZero, fromView: button)
if let indexPath = tableView.indexPathForRowAtPoint(point) {
}
//here's where I can't get reference to the headerView as mentioned above using .cellForRowAtIndexPath, .headerViewForSection
}