Ok I feel like an idiot that I can't get this working, and none of the other answers on SO are getting me anywhere.
I have a very simple UIView
that I have defined in a .xib and am loading as the tableHeaderView
of my UITableViewController
:
UIView* headerView = [[NSBundle mainBundle] loadNibNamed:@"ProfileHeaderView" owner:self options:nil][0];
self.tableView.tableHeaderView = headerView;
The file's owner of the header .xib is set to my controller class, and so far this much works fine. My outlets are connecting properly and I can set my labels to their correct values, etc.
But, when I added a UIButton
to my headerView, it is not responding to touches no matter what I try.
I've confirmed that the frames of the header and of the button are correct and both have userInteractionEnabled
as YES
.
I cannot for the life of me figure out why this isn't working. I am really not doing anything tricky here that I can think of.
Here's some debug info:
po self.tableView.tableHeaderView
<UIView: 0x17ef5420; frame = (0 0; 320 194); autoresize = W+H; layer = <CALayer: 0x17eda4a0>>
po self.loginButton
<UIButton: 0x17ec1630; frame = (80 164; 160 30); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x17eec760>>
Update: I discovered some new evidence. The above were logged inside viewDidLoad
, and the frames have their correct values. However, if I set a breakpoint in tableView:didSelectRowAtIndexPath:
, I notice that somehow my header view frame height has changed to 130 px!
po self.profileHeaderView
<UIView: 0x15eb6790; frame = (0 0; 320 130); autoresize = W+H; layer = <CALayer: 0x15eb67f0>>
I don't know what is causing this! Of course now that I know this, if I explicitly set the frame's height back to 194 in viewDidAppear:
it works fine. But I would obviously like to fix whatever is changing my frame in the first place.
The header still draws properly, and is the correct height (194 px) when it is rendered, but for some reason its frame is getting changed at some point, which is causing the button to fall outside of its frame and thus not receive touches.
What would be changing the header's frame like this? I don't have any constraints set up on it at all.