开发者

UITabBarController and switching from one tab to another through code

I have a UITabBarController that controls two tabs, Main and Settings.

Now I would like, under certain conditions, to switc开发者_JS百科h from the Main tab to the Settings tab (like if there is a setting the user have to do before he can use the App).

I know I can do this from the AppDelegate, but my condition could occur when I'm running in the Main view.

I have tried something like this:

    AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
delegate.rootController.selectedIndex = 1;

Where rootController is a UITabBarController defined in my AppDelegate.

The result from above code is that the tab change (eg the Settings tab is showed as active) but it still shows the Main view.

I'm sure there is a simple solution to this that I must have missed...

All suggestions are appreciated.


Have you tried:

self.tabBarController.selectedIndex = 1;

in the first viewController?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜