I'm having a UITableView
with custom cells. One cell navigates to another UINavigationController
. This cell contains a color label. When going back from the the new UIViewController
to the table view the color label lags displaying.
For better understanding I've made a video: http://youtu.be/zsWt97pxCu0
Why is this strange behavior? I thought the tableview stores it's state.
I've implemented tableView:cellForRowAtIndexPath:
which deques the cell from a NIB-file and tableView:willDisplayCell:forRowAtIndexPath:
which fills the red color label. Additional I've implemented the following for transition:
-(void) tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.section == 1) {
if(indexPath.row == 0) {
UIViewController* ctrl = [[UIViewController alloc] init];
ctrl.preferredContentSize = CGSizeMake(240, 200);
[self.navigationController pushViewController: ctrl animated:YES];
}
}
}
The "lag" is because of changes that take place in the cell when it is in the selected state. If you look very carefully at second 1.5 of your movie, you can see that the red rectangle has already vanished before we even leave the table view.
Thus, the sequence of events is:
The user taps the cell and it is selected. The red rectangle vanishes!
The new view controller is presented.
The presented view controller is popped, we come back to the table view, and the cell is still selected. While the cell is selected, the red rectangle is still not visible. Then, after a delay which is deliberately imposed by the table view controller, the cell is deselected - and the red rectangle reappears!
Basically you are hitting yourself in the face (hiding the red rectangle) and then complaining that your face is being hit. If you don't like being hit, don't hit yourself!
You have two choices:
Fix your red rectangle so that it is a red rectangle even when it is selected or highlighted. I can't tell you precisely how to do that because you have concealed the facts, not revealing anything about what this red rectangle is, how it is configured, etc.
Alternatively, set the table view controller's clearsSelectionOnViewWillAppear
to YES. This will cause the deselection to take place sooner. However, this is the lazy man's way; it would be better for you to figure out why your red rectangle vanishes when selected / highlighted.