3

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.

devios1
  • 36,899
  • 45
  • 162
  • 260
  • Try checking (and do `recursiveDescription`) after the layout has been updated per the latest comment in my answer. You're probably seeing 768 because this is the width specified in Interface Builder. – Timothy Moose Sep 01 '13 at 01:28

1 Answers1

1

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.

Timothy Moose
  • 9,895
  • 3
  • 33
  • 44
  • I already considered that, and set the buttons to be bound to the bottom of the view (turned off auto layout). See my update. – devios1 Sep 01 '13 at 00:07
  • 1
    Try putting a breakpoint in your view controller and doing `[self.tableFooterView recursiveDescription]` in the console. You may get a clue by seeing the footer's frame and view hierarchy. – Timothy Moose Sep 01 '13 at 00:12
  • 1
    It isn't a public API. Just type this in the console and it will work: `po [self.view recursiveDescription]`. Perhaps override `viewDidLayoutSubviews` and do it there. Or you can make your footer a custom view and debug there. For example, override `layoutSubviews` (where you'd just do `[super layoutSubviews]`). This gives you a place to set a breakpoint directly into your view's configuration. – Timothy Moose Sep 01 '13 at 00:48
  • It turns out the problem was the view's height was being set to 0 somewhere, even though it's clearly specified as 50 in the xib. If I explicitly set it back to 50 in `viewWillAppear` it works fine. Very strange indeed. I'd love to get to the bottom of this, but have other priorities to focus on now. – devios1 Sep 02 '13 at 17:44