
我在storyboard中创建了tabbar.我正在尝试使用以下代码以编程方式更改默认选项卡栏.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Make sure your segue name in storyboard is the same as this line
if ([[segue identifier] isEqualToString:@"TAB"])
{
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UITabBarController *tabBar = [storyboard instantiateViewControllerWithIdentifier:@"tabBar"];
tabBar.selectedViewController = [tabBar.viewControllers objectAtIndex:1];
}
}
Run Code Online (Sandbox Code Playgroud)
但它没有用.我怎么能这样做?它根本不起作用.
另外,当用户选择第一个标签时,我想回到主视图控制器.我们可以实现此功能.