【问题标题】:Need clarity on if I'm switching View Controllers correctly需要明确我是否正确切换视图控制器
【发布时间】:2014-10-23 00:52:18
【问题描述】:

我正在制作一个 ipad 应用程序,它在情节提要中有 11 个视图控制器,其中一个是主视图,其中包含用于控制其他视图控制器中的哪个显示为其子视图的按钮。

有没有人知道是否可以使用 UIViewControllers 作为其他 UIViewControllers 的子视图,并有来自苹果或其他来源的确凿证据?到目前为止,使用这种方法对我来说效果很好:

    int nextPage = (method to determine nextPage based on button pressed);
    [currentView.view removeFromSuperview];
    currentView = [self.storyboard instantiateViewControllerWithIdentifier:[NSString  stringWithFormat:@"page%i",nextPage]];
    [self.view insertSubview:currentView.view atIndex:0];
    [currentView.view setFrame:CGRectMake(0, 0, 1024, 768)];

网上有人说如果你用的是ios5或更高版本就可以了,但也有人说“NO NEVER DO THIS!!!”即使是ios5。其他人说要使用容器视图,但在我见过的使用容器视图的每个教程中,您最终只是在插入子视图后将视图控制器作为子视图插入到主视图中:

 [self.view addSubview:self.currentView];

我没有使用导航控制器,因为它们的可定制性有限,而且我不想要任何库存标签栏或导航栏,只需要所有自定义按钮。

提前致谢!

【问题讨论】:

    标签: objective-c xcode ios7 uiviewcontroller uistoryboard


    【解决方案1】:

    是的,当然,UINavigationControllerUITabBarController 的工作方式都是如此。 Interface Builder 将使用容器视图为您设置事件。

    Creating Custom Container View Controllers


    要点是处理childViewControllers 很重要。这可能有点棘手,但对于正确传播通知很重要。

    【讨论】:

    • 感谢您的意见。我刚刚在我拿起的一本书中读到了,没关系。
    猜你喜欢
    • 2023-03-11
    • 2016-11-16
    • 2013-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多