开发者

Changing tabBarController.selectedViewController only works once?

My iPhone app uses a UITabBarController. On the first tab, there's a scenerio where the user can go two UIViewControllers deep without changing tabs. So the screenflow is like this:

  1. App loads with first tab opened by default.
  2. User presse开发者_JAVA百科s a UIButton which takes them to second UIViewController in the same tab.
  3. From the second UIViewController, user can press another UIButton taking them to a third UIViewController, still in the same tab

This works when switching from the first UIViewController to the second with these 2 lines:

    2ndViewController = [[SecondViewController alloc] init];
    self.tabBarController.selectedViewController = 2ndViewController;

However, when I try to do the same from the second UIViewController to the third, it doesn't work. The button doesn't do anything, and I stay on the second UIViewController.

Can anyone explain why that is? Is there a workaround I can use? I'm happy to provide more code if needed.

Thanks in advance.


This isn't what that property was meant for. You are most likely experiencing the "undefined behavior" the documentation talks about.

The best way to do what you are doing is to place a UINavigationController in the tab and push each controller with that. If you don't want to show the navigation bar, you can hide that with navigationBarHidden.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜