Seg*_*gev 5 objective-c tabbar ios
我有一个带有5个标签的TabBar的应用程序(常规标签栏没有自定义类).当我启动应用程序时,左侧选项卡打开.我希望它首先打开中间的一个.我试过试试
[self.tabBarController setSelectedIndex:3];
Run Code Online (Sandbox Code Playgroud)
在ViewController的ViewDidLoad中,首先打开但是选项卡没有切换.
我可以看到它突出显示但未选中.如果我把上面的代码放在viewWillAppear它下面就会在第一次运行时被选中,但是当我不时地选择左边的标签时它会跳到中间的那个.
也尝试了这个没有成功:
DetailsViewController* vc = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailsViewController"];
[self.navigationController pushViewController:vc animated:true];
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
Seg*_*gev 10
这是唯一对我有用的解决方案.在appdelegate:
UITabBarController *tabBar = (UITabBarController *)self.window.rootViewController;
[tabBar setSelectedIndex:2];
Run Code Online (Sandbox Code Playgroud)