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

困惑了三天的 ContainerViewController 的问题,求大神指导

  •  
  •   pysama · 2015-05-24 13:08:52 +08:00 · 2961 次点击
    这是一个创建于 3268 天前的主题,其中的信息可能已经有所发展或是发生改变。

    当你连续想了太久的问题还没搞定,要么就是方法错了,要么就是脑袋少根经了?所以我整理下思路发到V2,希望得到指点。在下面的描述中,我用SB代替storyboard,使用VC代替ViewController. 谢谢理解。

    功能描述:

    点击一个按钮后,在container中显示对应的详情页面(detail)。

    storyboary描述:

    • 一个默认的VC中包含一个按钮和一个ContainerView;
    • 一个ContainerVC(这个是创建containerView时自动生成的);
    • 一个详情页面detailVC

    类描述:

    • ViewController (对应默认的VC)
    • wrapVC (对应containerVC)
    • detailVC (对应detailVC)

    我在wrapVC类中实现了addChild的方法

    //方法名没写全,但应该能表达意思
    -(void)addChild:(uivc*)child {
        [self addChildVC: child];
        //...set child view ...
        [self.view addSubView: detail.view];
        [detail didMoveToParentVC:self];
    }
    

    如果我在wrapVC中去调用addChild,前端是可以正常显示的

    然后在默认的VC类中的按钮点击事件中调用该上面的的方法:

    -(IBAction)trigger:(id)sender{
        detailVC* detail = [self.SB initVCWithID: @"detail"];
        //...get wrapVC using SB id...
    
        [wrapVC addChild:detail] ;
    
        //这里的count值都是正确的,但前端就是不显示detail
        NSLOG(@"children count %d", wrapVC.childVCs.count);
    }
    

    上面的步骤中,是哪里出了问题呢?

    谢谢大家了。

    3 条回复    2015-05-24 13:26:37 +08:00
    wujichao
        1
    wujichao  
       2015-05-24 13:20:27 +08:00
    等等 你的问题是什么 看了三遍没找到
    wujichao
        2
    wujichao  
       2015-05-24 13:21:18 +08:00
    "如果我在wrapVC中去调用addChild,前端是可以正常显示的"
    "[wrapVC addChild:detail] ; //这里的count值都是正确的,但前端就是不显示detail"
    这个不矛盾吗?
    pysama
        3
    pysama  
    OP
       2015-05-24 13:26:37 +08:00
    我的问题是,如何在rootVC中调用addChild方法,让detail页面在container中显示出来。


    @wujichao 不矛盾啊。前面一句是在wrapVC类中调用addChild方法。
    后面说的是在RootVC中调用 wrapVC的addChild方法。。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2365 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 11:34 · PVG 19:34 · LAX 04:34 · JFK 07:34
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.