【发布时间】:2012-04-28 18:05:51
【问题描述】:
在我的应用程序中,我尝试切换视图,每个视图都是它们自己的 XIB,同时使用自定义动画来执行此操作。我制作了一个基本视图控制器作为父视图来保存所有代码,但我似乎无法让它工作。
我为我的应用程序和界面构建器中的所有视图控制器制作了一个 IBOutlet,我将插座连接到正确的控制器。每个控制器也加载正确的 XIB,所以这些都不是问题。问题是以下更改视图代码。
这是我的代码:
-(void)changeViews {
CGRect frame = self.view.frame;
frame.origin.x = CGRectGetMaxX(frame);
theView4.view.frame = frame;
[self.view addSubview:theView4.view];
[self addChildViewController:theView4];
[self transitionFromViewController:theView1
toViewController:theView4
duration:1
options:UIViewAnimationOptionTransitionNone
animations: ^{
CGRect frame = self.view.frame;
theView4.view.frame = frame;
frame.origin.x -= frame.size.width;
self.view.frame = frame;
}
completion:completion:nil];
这是控制台崩溃:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Children view controllers <MyGameViewController: 0x1dd25210> and <Settings: 0x1dd249d0> must have a common parent view controller when calling -[UIViewController transitionFromViewController:toViewController:duration:options:animations:completion:]'
有谁知道如何解决这个问题?
谢谢!
【问题讨论】:
-
“设置”类到底是什么?它是如何定义的?
-
设置类是一个 UIViewController,它在头文件中声明,经过设置和获取,并连接到 Interface Builder 中的 View Controller 出口,该出口通过其属性连接到设置 nib 和类。
标签: ios ios5 view uiviewcontroller transition