开发者

How to navigate back home using Monotouch

I've got my MonoTouch app setup to use a TabBar and navigation controllers. I set HidesBottomBarWhenPushed = true as soon as I get to view 1 or view 3.

E.g.

TabBar
   -Options 1 Navigation Controller
      -View1
      -View2
   -Options 2 Navigation Controller
      -View3

I can use the navigation controllers to move between views with a back button and everything is working as expected.

The problems comes when the current location is view1 or view3. How do I navigate back to the tabBar开发者_运维百科 level? I can add a Back button manaully, but what logic should be under the button? I really need a TabController.PopToRootLevel(), but I can't find a similar method????

Edit: This code works, but I this doesn't look right. Its not animates and I presume this will cause memory leaks.

this.TabBarController.SelectedIndex = 0;


The method you are looking for is PopToRootViewController and it is inside the UINavigationController class. So, inside the view controller from which you want to return to the start, call this (in your custom back button, or the button you will use):

this.NavigationController.PopToRootViewController(true);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜