Skip to content

Instantly share code, notes, and snippets.

@ryanfitz
Created June 15, 2015 04:11
Show Gist options
  • Save ryanfitz/b3eaeb0dba45c3d63ff3 to your computer and use it in GitHub Desktop.
Save ryanfitz/b3eaeb0dba45c3d63ff3 to your computer and use it in GitHub Desktop.
asdk header node workaround
func tableView(tableView: UITableView!, viewForHeaderInSection section: Int, delegate : PollHeaderNodeDelegate?) -> UIView! {
var view = tableView.dequeueReusableHeaderFooterViewWithIdentifier("Header") as? UITableViewHeaderFooterView
if view == nil {
view = UITableViewHeaderFooterView(reuseIdentifier: "Header")
}
view?.backgroundView = UIImageView()
let contentView = view!.contentView
contentView.backgroundColor = UIColor.clearColor()
if let vm = self.sectionedDS.data?[section] {
contentView.tag = vm.id.hashValue
} else {
contentView.tag = -1
}
for subview in contentView.subviews {
subview.removeFromSuperview()
}
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)) {
[weak self] in
var header = self?.tableView(tableView, loadNodeForHeaderInSection: section)
if let pollHeaderNode = header as? PollHeaderNode {
pollHeaderNode.delegate = delegate
}
var size = header?.measure(CGSizeMake(CGRectGetWidth(tableView.bounds), CGFloat.max))
header!.frame = CGRectMake(0, 0, size!.width, size!.height)
dispatch_async(dispatch_get_main_queue()) {
if let pollHeaderNode = header as? PollHeaderNode {
if contentView.tag == pollHeaderNode.pollViewModel.id.hashValue {
contentView.addSubnode(header)
}
}
}
}
return view
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment