使用viewController打开同一个viewController的另一个实例

时间:2010-10-07 08:02:27

标签: iphone uiviewcontroller transition

我有一个MasterViewController.h.m.xib(UIViewController),它以下列方式打开TestDummy.h.m.xib(UIViewController):

TestDummy *controller = [[TestDummy alloc] initWithNibName:@"TestDummy" bundle:nil];
[scrollView addSubview:controller.view];

我在TestDummy中有两个按钮:(打开),(关闭)和一个标签:( windowDepth)。

我正在尝试创建一个由第一个TestDummy打开的第二个实例TestDummy。然后允许多个TestDummy(UIViewController)打开N深度并允许关闭按钮将它们恢复到零深度。这是我打开按钮的内容。

-(IBAction) btnOpen_Clicked{
TestDummy *newController = [[TestDummy alloc] initWithNibName:@"TestDummy" bundle:nil];
newController.isNotRoot = YES;
newController.windowDepth = self.windowDepth + 1;
//do stuff...
childDummy = newController;

// start the animated transition
[UIView beginAnimations:@"page transition" context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];

//insert your new subview
[self.view addSubview:newController.view];

// commit the transition animation
[UIView commitAnimations];
[newController release];

}

当我这样做时,我在调试控制台中收到错误。

2010-10-07 00:59:12.549 OrionClient[5821:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType btnOpen_Clicked]: unrecognized selector sent to instance 0x6a339a0'

必须是内存管理问题,但我无法弄明白。

提前致谢。

3 个答案:

答案 0 :(得分:0)

  

'NSInvalidArgumentException',原因:   ' - [__ NSCFType btnOpen_Clicked]:   无法识别的选择器发送到实例   0x6a339a0'

这意味着您正在尝试在该实例上调用非现有方法。你是如何定义btnOpen_Clicked选择器的?我猜它应该看起来更像,但真的需要看看你如何定义选择器。

-(IBAction) btnOpen_Clicked:(id)sender

答案 1 :(得分:0)

这意味着应用程序无法找到您的方法btnOpen_Clicked

首先使用以下命令重命名您的方法:

-(IBAction) btnOpen_Clicked:(id)sender

然后确保此方法规范位于.h文件中 在InterfaceBuilder中使用TestDummy.xib,还要确保按钮和此方法之间的链接正确完成,例如TouchUpInside事件。

答案 2 :(得分:0)

解决了它删除了最后一行[newController release];我需要找出实际上正确调用它的位置。