2011-01-28 72 views
3

我有一个应用程序,我创建为选项卡栏应用程序,并且有3个选项卡(主页,搜索,我的帐户)。主视图加载一些信息和搜索按钮。搜索按钮然后将用户带到搜索视图,但由于用户没有选择标签,所选标签仍然是主页标签。一旦搜索viewDidLoad,我如何将所选标签从主页更改为搜索?更改UITabBar选定标签

回答

8

感谢您的帮助,你们帮我在我结束了使用的应用程序代理访问的UITabBarController正确的方向。这就是它的样子。

Motel_6AppDelegate *appDelegate = (Motel_6AppDelegate*) [[UIApplication sharedApplication] delegate]; 
    [appDelegate.rootController setSelectedIndex:1]; 
4

阅读文档。从搜索控制器内,您可以拨打:

self.tabBarController.selectedViewController = self; 

UITabBarController也有selectedIndex财产,如果这对你更方便。但是,viewDidLoad可能是放置此代码的错误位置,因为每次显示搜索控制器时都可能不会调用它。您应该直接从用户点击主屏幕上的搜索按钮时调用的操作内部选择选项卡。

3

使用tabBarController.selectedIndex = intIndex; // inyour情况1

使用内部applicationDidLaunch这段代码

0

这个片段对我的作品在iOS7和Xcode的5

- (IBAction)cancelButtonPressed:(id)sender 
{ 
    [self.tabBarController setSelectedIndex:1]; 
} 
故事板内