我在故事版中创建了选项卡栏,现在我想使用以下代码通过编程方式更改默认选项卡栏。
- (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];
}
}
但它没有起作用。我该怎么做?它根本不起作用。
另外,当用户选择第一个选项卡时,我想回到主页视图控制器。我们如何实现这个功能。
prepareForSegue
在 segue 即将执行时被调用。 - toasted_flakes