Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIButton in custom UITableViewCell stop working after rotation

Problem:

I used custom UITalbeViewCell that contains two buttons, they work fine in the portrait orientation. After the rotation, they all stop responding to the button touch up inside function. Some people having problems that their buttons couldn't drew correctly after rotation. Mine looked fine since the buttons are showing in the right places after rotation, but they do not respond to the button press anymore.

For this specific view in my app, I used a UIPageController to implement multi pages in a view, and for the view (name it EmbeddedView for now) embedded in the page's scroll controller, there is a UITableView that contains custom UITableViewCell. Custom table view cell only has a nib, the file's owner is EmbeddedView.

in EmbeddedView:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
/*===== This is the most memory efficient way of creating table view cells =====*/

static NSString *CellIdentifier = @"CellIdentifier";

CustomTableViewCell *cell = (CustomTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
    [[self customTableCellNib] instantiateWithOwner:self options:nil];
    cell = [self customTableCell];
    [self setCustomTableCell:nil];
    }
}

What I tried:

I created another nib file for the custom table view cell and used it in -cellForRowAtIndexPath(), I checked the orientation and dynamically create the cell by using different nib, no luck.

I added [tableview reloadData] in -didRotateFromInterfaceOrientation(), didn't do anything.

Would someone point me to the right direction please? Any help is appreciated.

This is the table view Autosizing in IB:

enter image description here

It looks right but the buttons are not working

enter image description here

Update: I tried to specify different Autosizing masks in IB for the table view, and the results are showing below:

<1>

enter image description hereenter image description here

enter image description here

<2>

enter image description hereenter image description here

enter image description here

<3>

enter image description here

enter image description here

<4>

enter image description here

enter image description here

like image 322
Raymond Wang Avatar asked Jan 17 '13 20:01

Raymond Wang


1 Answers

Have you checked how the superview is being resized?

Check if the superview has 'clip to bounds' checked. If it is not check it. That will make the view clip its contents so you see if it is resizing ok.

I'd say the superview is not sizing correctly and because of that the touch events are not well delivered also.

EDIT - So this was the tip that could let the OP reach the solution:

What I normally do in cases like of unexpected behavior in resizing and such is to change every view in the hierarchy to a different, well recognizable, color. Right now you have view A and view B with the same background color (or clear) and you don't see if view B is resizing well. Good luck.

like image 126
Fábio Oliveira Avatar answered Nov 01 '22 16:11

Fábio Oliveira