使用情节提要中的选项卡控制器以编程方式打开视图 [英] Open a view programmatically with tab controller from storyboard
问题描述
我有一个故事板,具有以下视图(场景):
I have a storyboard which has following views (scenes):
- 登录屏幕
- 带有4个选项卡的"TabBarController"(库",工作流",设置"和下载"
基于通过单击按钮(登录)进行的用户登录,我以编程方式使用以下代码始终将第一个选项卡加载到选项卡栏控制器:
Based on user login by clicking on the button (Sign in), I programatically load tab bar controller with always first tab with following code:
LibraryWebViewContoller *lbc = [self.storyboard instantiateViewControllerWithIdentifier:@"docovaMainTabBarController"];
[self presentViewController:lbc animated:YES completion:nil];
我想要做的是能够从情节提要中使用TabBarController以编程方式打开不同的选项卡.到目前为止,我能够使用第一个选项卡打开选项卡栏控制器,但是打开其他选项并没有运气,因为它似乎总是在选择了第一个选项卡的情况下加载TabBarController.
What I want do is be able to open different tabs programmatically with TabBarController from storyboard. So far I am able to open the tab bar controller with first tab but no luck in opening others as it always seem to load the TabBarController with first tab selected.
推荐答案
我能够使用以下代码解决此问题:
I was able to solve the issue by using following code:
UITabBarController *tbc = [self.storyboard instantiateViewControllerWithIdentifier:@"docovaMainTabBarController"];
tbc.selectedIndex=1;
[self presentViewController:tbc animated:YES completion:nil];
此外,请记住编辑情节提要,并将UITabBarController的情节提要ID设置为docovaMainTabBarController,以便可以在情节提要中唯一地标识它.
Also, remember to edit the storyboard and give the UITabBarController a storyboard ID set to docovaMainTabBarController so it can be uniquely identified within the storyboard.
let tbc = self.storyboard.instantiateViewController(withIdentifier:"docovaMainTabBarController") as! UITabBarController
tbc.selectedIndex = 1
self.present(tbc, animated: true, completion:nil)
这篇关于使用情节提要中的选项卡控制器以编程方式打开视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!