ios - 父 View Controller 调用自身而不是 subview

标签 ios uiviewcontroller addsubview

我正在(尝试)实现一个主视图 Controller 容器,首先实例化介绍 View Controller ,然后再实例化实际的应用程序 View Controller 。但是我无法让它工作,我觉得我缺少一些非常基本的东西。介绍 View Controller 在 initWithFrame 中加载介绍 View :

使用以下界面:

@interface ViewControllerMain : UIViewController
@property (strong, nonatomic) ViewControllerIntroduction *viewControllerIntroduction;
@end

和下面的实现

@implementation ViewControllerMain

- (void)loadView
{
    //  Instantiate the view controller for the adventure view
    self.viewControllerIntroduction = [ [ [ ViewControllerIntroduction alloc] init ] autorelease ];
}

- (void)viewDidLoad
{
    [ super viewDidLoad ];

    //  Instantiate the view controller for the introduction view
    [ self addChildViewController: self.viewControllerIntroduction ];
    [ self.view addSubview: self.viewControllerIntroduction.view ];
    [ self.viewControllerIntroduction didMoveToParentViewController: self ];
}

@end

当我越过 addSubView 语句时,它会退回到 addChildViewController 语句。

我已经尝试解决这个问题几个小时了,我们将不胜感激。

最佳答案

只有在显式创建 View Controller 的 View (self.view) 时,才应覆盖 -loadView 方法。删除您的 -loadView 方法并将 self.viewControllerIntroduction 的初始化移动到 -viewDidLoad

关于ios - 父 View Controller 调用自身而不是 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14155336/

相关文章:

ios - 如何在不失去对导航栏的访问权限的情况下更改 View Controller 中可访问性元素的顺序?

ios - 时区问题 "ZE8",如何将NSDate转换为NSString

ios - 在 iOS 中用另一个实际图像掩盖透明图像

objective-c - UIView 大小和 UIWindow rootViewController

uiviewcontroller - UIModalPresentationCurrentContext - 未调用旋转方法

ios - 如何正确设置 UINavigationController 并将 View 添加到堆栈

ios - 将 NSString 从 plist 传递到 ImageView 时遇到问题

javascript - 在 mobile safari 的 div 中时 iframe 被剪切

ios - 带有 .OverCurrentContext 的 UIViewController 与 .CrossDissolve 不透明

interface-builder - 苹果界面生成器 : adding subview to UIImageView