点击 UITabbarController 子页面的按钮时,如何用 push 类型跳转到新的 DetailVIewController

2015-05-20 16:35:50 +08:00
 pysama

最开始的做法:使用segue将UITabbarController子页面的按钮和DetailVIewController连接起来,此时类型只能选择modal风格或其他,一旦我选择push风格,build时就会报错—“push只能应用在navigatorController中”。

我继续尝试过:将一组UINavigator页面(一个RootViewController和一个DetailViewController)嵌入到UITabItem,功能确实实现了,但是不完美,跳转到DetailViewController时,应用底部的tabbar一直存在。我要的效果是,在页面跳转的时候,tabbar也一起被push到左侧去。就好像整个UITabbarController的内容都被push到左侧隐藏了。

希望得到大家的帮助,谢谢!

3857 次点击
所在节点    iDev
6 条回复
black
2015-05-20 16:46:03 +08:00
DetailViewController *detail = ...;
detail.hidesBottomBarWhenPushed = YES;
self.navigationController push...

懂了吗?
black
2015-05-20 17:04:01 +08:00
UITabBarController 嵌入一组 UINavigationController (每个 tab 对应一个) 是很典型的 UI 结构,hidesBottomBarWhenPushed 属性也正是为了满足楼主你这种普遍需求设计的。
pysama
2015-05-20 17:23:03 +08:00
@black 你的答案直观明了,晚上回家再试试
非常感谢哈。
plutodai
2015-05-20 17:29:26 +08:00
如果不想push的时候tabbar也被push到左侧去的话,你可以这么做:

将RootViewConroller嵌入到UINavigationController中
RootViewConroller *rootVC = [[RootViewConroller alloc] init];
UINavigationController *rootNaVC = [[UINavigationController alloc] initWithRootViewController:rootVC];
UITabbarController *tabbarC = [[UITabbarController alloc] init];
[tabbarC setViewControllers:@[rootNaVC]];
self.window.rootViewConntroller = tabbarC;
pysama
2015-05-20 21:27:48 +08:00
弄好了,真棒~
顺便优化下,在rootVC的页面不显示navBar

- (void)viewWillAppear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:YES animated:animated];
}

-(void)viewWillDisappear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:NO animated:animated];
}
pysama
2015-05-20 21:28:47 +08:00
@plutodai 我做的demo中,默认情况就是:tabbar不会被push到左侧去呢。
还是感谢哈~

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/192489

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX