我有 UIViewController
和 UITabBarController
.UIViewController
包含 5 个按钮,UITabBarController
有 5 个选项卡.
I have UIViewController
and UITabBarController
.
UIViewController
contain 5 buttons and UITabBarController
has 5 Tabs.
通过点击第一个按钮应用显示 TabBarController
与第一个选定的选项卡,第二个 - TabBarController
与第二个选项卡,依此类推...
By tapping first button app shows TabBarController
with the first selected tab, second - TabBarController
with the second tab and so on...
为了准备这个,我对每个按钮都使用了 Modal-segue
.
To prepare this I have used Modal-segue
for every button.
一切正常.
现在我需要在 TabBarController
的 UINavigationBar
上创建主页"按钮(可能以编程方式),它将执行返回主页视图"操作.
Now I need to create "Home" button (may be programmatically) on TabBarController
's UINavigationBar
, which will execute "Go home view" action.
编辑了更多细节
{见下面的截图}
1 和 2 之间有两个模态转场(两个按钮 - 两个转场)
There are TWO modal-segues between 1 and 2 (two buttons - two segues)
在 UIViewController 中的 prepareForSegue 中:
In my prepareForSegue in UIViewController:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
AppDelegate *d = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if ([segue.identifier isEqualToString:@"s1"]) {
d.initialTab = 0;
}
else if ([segue.identifier isEqualToString:@"s2"]) {
d.initialTab = 1;
}
}
在我的 viewDidLoad 中的 UITabBarController:
In my viewDidLoad in UITabBarController:
TabController *mainTabController = (TabController *)self;
AppDelegate *d = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[mainTabController setSelectedIndex:d.initialTab];
这是可行的!
但是我需要回到主页.因此,如果 TabBarController 之后有 NavigationController,我想在 NavigationBar 中创建一个按钮.
But I need to go back to home-page. So if there is a NavigationController after TabBarController I would like to create a button in NavigationBar.
我建议你以一个 Navigation Controller 作为父级.
然后,将您的启动视图添加为它的根视图.
I suggest you to take a one Navigation Controller as a parent.
Then, add your Startup View as a root view of it.
在您的主视图控制器页面上,
On your main view controller page,
- (void)viewWillAppear:(BOOL)animated
{
self.navigationController.navigationBarHidden = NO;
}
因此,它将隐藏您的主导航.所以无需担心这个内部导航流程.
而对于内部导航,您已经采用了不同的导航控制器.
So, it will hide your main navigation. So no need to worry for this internal navigation flow.
And for internal navigation, you have already taken different navigation controllers.
通过使用代码:
[self.parentViewController.navigationController popToRootViewControllerAnimated:YES];
您将位于应用程序的根目录,它将弹出所有堆叠在应用程序中的视图控制器.
you'll be at root of the application and it will poped out all view controller which were stacked in application.
希望您能理解流程和如果您感觉良好,将申请.
Hopefully, you'll understand flow & will apply if you feel good.
享受编码.
谢谢.
Enjoy Coding.
Thanks.
这篇关于如何进入“主页"在 iOS 应用程序中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!