【发布时间】:2012-07-25 22:21:37
【问题描述】:
我有 1 个视图控制器充当 CustomViewContainer,它有 2 个子视图控制器,最初在启动时仅添加了 1 个。
从子容器上调用addChildViewController,然后在子设备上调用didMoveToParentViewController,不会在屏幕上显示我的子视图。相反,我仍然看到父控制器的视图。
@implementation ContainerViewController // inherits from UIViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
LOG_METHOD_SIG();
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])
{
// ChildViewController is a subclass of UIViewController
_childController = [[ChildViewController alloc] initWithNibName:nil bundle:nil];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self addChildViewController:_childController];
// Expected the following line to display the child controller's view
[_childController didMoveToParentViewController:self];
}
如果我在'addChildViewController' 之后添加[self.view addSubview:_childController.view],则会显示视图。但我认为容器视图控制器的全部意义在于避免直接操作视图。
在您添加第一个子视图控制器的情况下,您可以调用“transitionFromViewController”吗?如果可以,“from”视图控制器是什么?
【问题讨论】:
标签: ios5 uiviewcontroller