Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 7 UITableView didSelectRowAtIndexPath pushViewController programmatically, Animation issue

EDIT: I have Found the answer to my own question. Please look at the bottom of my post.

I am having an animation issue trying to push a UIViewController in didSelectRowAtIndexPath on a UITableView programmatically. When I run this code in iOS 6 it works fine. In iOS 7 the animation is messed up (it animates to the left about 20% of the screen then disappears). If I do this in storyboard the animation is fine. Am I missing something or is there a way around this without using storyboard?

// This is a cut down example.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UIViewController *viewController = [[UIViewController alloc] init];
    [self.navigationController pushViewController:viewController animated:YES];
}

This is what it looks like right before the tableView disappears. I understand why it does this. Its because the new view being pushed should animate sliding in over it as it does when using storyboard. For some reason it does not work programmatically.

enter image description here

EDIT: This is all I missed For some reason you have to set a backgroundColor.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UIViewController *viewController = [[UIViewController alloc] init];
    [viewController.view setBackgroundColor:[UIColor orangeColor]];
    [self.navigationController pushViewController:viewController animated:YES];
}
like image 589
Jaybit Avatar asked Oct 08 '13 18:10

Jaybit


1 Answers

This is the default "parallax" behavior triggered by the pushViewController:animated: method in iOS7.

Having little experience with storyboards I suspect that their segues are different from UINavigationController push/pop animations.

You can override the default push/pop by building custom animated or custom interactive transitions.

Or you could use the UIViewController method:

transitionFromViewController:toViewController:duration:options:animations:completion:

to customize this behavior. Hope this helps and hope I've understood your question...

like image 177
Alfie Hanssen Avatar answered Sep 19 '22 11:09

Alfie Hanssen