Search code examples
objective-cuitableviewtablefooterview

Very strange UITableView tableFooterView behavior


I'm trying to add a simple table-wide footer view from a nib to my UITableView, but for some reason the footer is showing up always one row too high, and the buttons are not responding at all to taps (in fact the touch actually goes right through to the cell behind the button):

enter image description here

I can't figure out why the footer isn't going in it's correct spot. I've accounted for its height explicitly in the size of the UIPopoverController it is contained within.

Here's how I'm creating/adding the footer view:

self.tableFooterView = [[NSBundle mainBundle] loadNibNamed:@"ModifierFooterView" owner:self options:nil][0];
self.tableView.tableFooterView = self.tableFooterView;

Update: The buttons are bound to the bottom left and bottom right corners respectively:

enter image description here

Also for a clue I tried setting the entire background color of the footer view to bright green. As you can see from the previous screenshot it's not showing green anywhere.

Update 2: When logging the frame values of the footer view at the time I load it from the nib after seting it as the table's footer, it has the correct Y value that would place it right after the last row. The only slightly odd reading is the width is 768 instead of the width of the parent view.

Update 3: Turns out the issue is being caused by the loaded footer view somehow getting its frame height set to 0 somewhere. I still haven't figured out where/why this is happening, but if I explicitly set it back to 50 when the view is about to appear, things work properly so it's no longer a major issue. However, if anyone has insight on why this is happening, do please post the answer.


Solution

  • If touches are passing through your views, it means they lie outside of their parent view's bounds. Looking at your screenshot, I'm guessing the darker gray bar is the actual footer view. And for some reason, the buttons inside it are getting pushed up and out-of-bounds.

    The most likely reason is that, when the view is inserted into the table, it is given a smaller height than in the XIB layout, causing the buttons' struts & springs (or Auto Layout constraints) to push them up. So you just need to adjust your struts & springs (or constraints). If you can share more details about your layout, I can give you more specific instructions.