小编use*_*340的帖子

以编程方式更改选项卡栏

在此输入图像描述

我在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)

但它没有用.我怎么能这样做?它根本不起作用.

另外,当用户选择第一个标签时,我想回到主视图控制器.我们可以实现此功能.

storyboard ios

5
推荐指数
1
解决办法
5566
查看次数

标签 统计

ios ×1

storyboard ×1