V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
pysama
V2EX  ›  iDev

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

  •  
  •   pysama · 2015-05-20 16:35:50 +08:00 · 3850 次点击
    这是一个创建于 3265 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

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

    6 条回复    2015-05-20 21:28:47 +08:00
    black
        1
    black  
       2015-05-20 16:46:03 +08:00
    DetailViewController *detail = ...;
    detail.hidesBottomBarWhenPushed = YES;
    self.navigationController push...

    懂了吗?
    black
        2
    black  
       2015-05-20 17:04:01 +08:00   ❤️ 1
    UITabBarController 嵌入一组 UINavigationController (每个 tab 对应一个) 是很典型的 UI 结构,hidesBottomBarWhenPushed 属性也正是为了满足楼主你这种普遍需求设计的。
    pysama
        3
    pysama  
    OP
       2015-05-20 17:23:03 +08:00
    @black 你的答案直观明了,晚上回家再试试
    非常感谢哈。
    plutodai
        4
    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
        5
    pysama  
    OP
       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
        6
    pysama  
    OP
       2015-05-20 21:28:47 +08:00
    @plutodai 我做的demo中,默认情况就是:tabbar不会被push到左侧去呢。
    还是感谢哈~
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   894 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 22:10 · PVG 06:10 · LAX 15:10 · JFK 18:10
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.