Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button in custom UITableViewCell not responding in iOS 7

This is more or less a continuation of this post: Button in UITableViewCell not responding under ios 7

I am having the same exact issue and have tried every suggestion in the thread. Obviously I don't own that question so I can't edit it to give more info, and thus why I am posting this question now!

Problem:

I have VC nib that I load up that has a tableview in it that I resize based on how many rows are in it. Each row is made from a custom uitableviewcell subclass using a nib file. That class/nib has 4 buttons in it. I can load this code up in iOS 6 or iOS 8 right now and it works perfectly. I don't have a iOS 7 device so I'm bound to the simulator which is at 7.1 (which is the version I'm guess the user that reported this issue was using as well given it was today). Now in the simulator, and the user's phone, I can touch/click everything else on that VC except any of the buttons in the cells. It's as if they had UserInteractionEnabled set to NO, but they don't and neither are any of their parent views (as I'll soon get into).

Tried solutions:

-Completely recreating the nib from scratch both using and not using autolayout

-Calling [self.contentView addSubview:button] in the awakeFromNib of the cell class

-Tried re-adding the buttons to the contentView at runtime with [self.contentView addSubView:button]

-Have ensured four times over that every view in the hierarchy I can find that leads to these buttons have userInteractionEnabled set to YES. (including but not limited to the tableview itself, the cell, the contentView and when I added a "parent view" to the buttons that it was set as well)

-Tried raising all the buttons with a parent view that contains nothing but the buttons

-All buttons are at the top(visually bottom) of the event stack(add and remove are the other two buttons): Hierarchy List

-Have set the table cell selection from single to none.

-I am not overriding layoutSubviews in my cell class

-I can not move any views outside of the Content View as Interface Builder takes them completely out of the cell if I do that.

-I have tried disabling the userInteractionEnabled on just the ContentView at runtime with no change

-I tried putting in the cell creation code of the tableview [cell bringSubviewToFront:cell.button]; for the different buttons to the same result.

Hopefully Helpful Facts:

-I tried setting all of the background colors of all of the views in the hierarchy to different colors so I could visually debug it at runtime... it looked exactly as expected. No overlaps or coverings. (This was limited to only views in the cell)

-Here is all of the settings for the TableView: TableView SS 1TableView SS 2

-I tried to load this in the new XCode 6 to use the visual debugger but the 7.1 simulator included with it actually ran the code perfectly so I could debug it...

-Here is the dequeueing code in the VC:

NiTGroupTimeCell* cell = (NiTGroupTimeCell*)[tableView dequeueReusableCellWithIdentifier:ident forIndexPath:indexPath];

-Here is the code in the viewDidLoad of the VC to set up the cell nib with the table(it's 2 because this is the from scratch one):

[self.timesTable registerNib:[UINib nibWithNibName:@"NiTGroupTimeCell2" bundle:nil]  forCellReuseIdentifier:@"GroupTime"];

-All connections were made via IB. These are all using IBAction or IBOutlet.

-I have NSLog statements in all button methods to test if they are actually called, but I have also tested with breakpoints. All are never triggered in testing.

-The only TableView delegate or datasource methods implemented are as follows:

-(int)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
-(float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

-As per suggestion I took Revel to it and found that a mystery UILabel and UIImageView were in the view.... but as you can see their frames are all zeros so they shouldn't be getting in the way of anything so back to where we were I'm afraid:

Layers

Hierarchy List from Revel

UILabel frame: UILabel frame

UIImageView frame: UIImageView frame

IIRC I counted this off as a Simulator bug before, but since it's happening on the user's device it must be an actual issue and it's holding up my pipeline so help would be GREATLY appreciated! Thanks in advance!

PS I'm happy to post whatever, but because of all the shifting in debugging I didn't know exactly what people would want to see and I didn't want to overload this post because I knew it was going to be long with everything else.

like image 760
Matthew Clark Avatar asked Jul 31 '14 04:07

Matthew Clark


1 Answers

So apparently the issue was these lines of code(in diff format from my git diff output):

--(int)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
+-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

and

--(float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
+-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

so yeah... seems that in iOS7+ if you have the "old" output types for these datasource methods it'll look fine but bork your tableview functionally... good times, but hey it's fixed now^^ hopefully this helps others.

like image 134
Matthew Clark Avatar answered Nov 15 '22 06:11

Matthew Clark