开发者

UINavigationView Problem

开发者 https://www.devze.com 2023-03-24 08:38 出处:网络
I build a navigation view controller in a tab bar based app. In the controller, the app presents a map view with some annotations. On the navigation bar, there is a bar button \"List开发者_高级运维\".

I build a navigation view controller in a tab bar based app. In the controller, the app presents a map view with some annotations. On the navigation bar, there is a bar button "List开发者_高级运维". When user press the button, a table view containing the list of annotations will be pushed into the navigation stack. In the table view, I also implement a custom bar button, if user press the button, the map view will be popped into the navigation controller.

Here comes the problem, this app works fine, but if I press the "List" button, and once the tableview controller loaded, I switch back to map view by pressing the "Map" button to go back, then switch the views like this several times. First the view switches fine, but after a few circles (after several tests, this number is 3), when I press the "List" button again, the problem shows like this: The tableview seems pushed into the stack (from the back button shown on the navigation bar), but the tableview didn't show up, it's still the map view showing. If I press the back button now, the root view controller in the navigation controller shows, but when I want to switch back to child view controller (the tableview controller), the app terminates.

Sorry, I cannot insert the image in this question, but you can the problematic screenshot here: http://i.stack.imgur.com/hNYsX.png

Here is the code I switch between view controllers:

In the root view controller of the navigation view controller:

ListViewController *flipListViewController = [[ListViewController alloc]initWithStyle:UITableViewStylePlain];
AppDelegate *delegate = [[UIApplication sharedApplication]delegate];
UINavigationController *navController = [delegate navigationController];
//Flip Animation
[UIView beginAnimations:nil context:nil];
[navController pushViewController:ListViewController animated:NO];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.7];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:navController.view cache:NO];
[UIView commitAnimations];
[navController release];
[flipListViewController release];

Here I custom the transition animations. In the child view (the table view controller), I use the following code to pop up the root view controller.

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.7];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[self.navigationController popViewControllerAnimated:NO];
[UIView commitAnimations];


It seems you are using app Delegate's navigation controller while you should use self.navigationController for push and pop. Also there is no need to use the animation block you can use modalTransitionStyle for flip effect. Try pushing viewController using self.navigationController.

0

精彩评论

暂无评论...
验证码 换一张
取 消