开发者

Navigating View Hierarchy From A Modal UIViewController

I'm developing an application using a number of UIViewControllers linked using a UINavigationController. The UINavigationController is set up to have a main menu as its default view. The main menu has two buttons that when pressed display one of two other UIViewControllers. So I have a simple two-layer view hierarchy that looks something like this...

Main Menu (UIViewController)
|
 ---- Menu Option 1 (UIViewController)
 ---- Menu Option 2 (UIViewController)

Now I would like my Menu Option 1 UIViewController to display another UIViewController as a modal view - which works fine. However开发者_如何转开发, I would also like to be able to jump directly from this modal view to the Main Menu...

Main Menu (UIViewController) <--------------
|                                           |
 ---- Menu Option 1 (UIViewController)      |
      |                                     |
       ---- Modal View (UIViewController)   |

Knowing that the UINavigationController is a stack and I need to pop my modal view and the next item I'm wondering how it's even possible....

Is there a simple way to do this without adding a callback method to the Menu Option 1 UIViewController?

I'm happy to take feedback on my implementation as well - something doesn't seem right about this!


UINavigationController has methods -popToRootViewControllerAnimated: and -popToViewController:animated: which you can use to pop the navigation stack back to a specific view controller. So, you could have the modal controller dismiss itself and then call

[self.navigationController popToRootViewControllerAnimated:YES];

That said, make sure that doing something like that is going to make sense to your users. An important aspect of the navigation style is that the user remembers how they got to a given point in the app, and they expect to be able to go back through those same controllers. If it works for your app, though, -popToRootViewControllerAnimated: is the way to implement it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜