Ali Baqbani Ali Baqbani - 1 year ago 102
iOS Question

Get tableView from custom UITableViewHeaderFooterView

I have a problem iterating over custom

UITableViewHeaderFooterView
's superviews to get its ancestor
tableView
but it returns nil and does not reach
tableView
at all. This solution works with
tableView
cell though.

Please note that I use custom UITableViewHeaderFooterView with Nib for sectionHeader or footer.

This is my code to get super view:

var parentView = self.superview

while (parentView != nil && !(parentView is T)) {
parentView = parentView?.superview
}

Answer Source

I iterating the custom UITableViewHeaderFooterView's superviews when tableView not assigned itself to header view. So I override didMoveToSuperview() method in my class and my problem was gone.