ios sdk only one view changes at a time bug
I'm pushing a number of views:
- the top one is a UITabBarController
- the second one is a UINavigationController with a pushed view
- the third one is a modal box.
Once the close button in the modalbox is pressed I'm trying to revert everything to the default state and change the tabbar index.
[self dismissModalViewControllerAnimated:YES];
[self.navigationController开发者_如何学编程 popViewControllerAnimated:NO];
[self.tabBarController setSelectedIndex:3];
This dismisses the modal view but doesn't do anything else. Any ideas what could be wrong? I read something about a possible ios bug but I don't know how to work around it.
Neither UITabBarController
nor UINavigationController
is a view. Both are subclasses of UIViewController
and have a property NSArray *viewControllers
.
If you have an actualView
controlled by an ActualViewController
that is pushed on top of a rootView
controlled by a RootViewController
that is the rootViewController
for the navigationController
, and you also have a modalView
controlled by a ModalViewController
, then put
[self dismissModalViewControllerAnimated:YES];
in ModalViewController.m
, and put
[self.navigationController popViewControllerAnimated:NO];
in ActualViewController.m
(from whence modalView
is pushed, presumably), and put
[self.tabBarController setSelectedIndex:3];
in RootViewController.m
(from whence actualView
is pushed, presumably).
If modalViewController
was never added to the navigationController
, then it doesn't know that the navigationController
exists.
If actualViewController
was never added to the tabBarController
, then it doesn't know that the tabBarController
exists.
The easy (and dirty) way: Dismiss the modal view in the modal view. Make the navigation view controller the delegate of the modal view. Make the tabbar controller the delegate of the navigation controller. When the button is pressed call a method in the navigation controller that pops the view and calls a method of the tabbar controller which changes the selected tab.
精彩评论