2013-02-14 47 views
0

在我的项目中,有10个视图控制器。在其中一个视图控制器中,我在xib中增加了一个视图控制器,以提供额外的功能(一个实际视图+为单个类添加视图控制器)。当我尝试将其actaul视图中的ie.navigate移动到添加视图控制器时,第一次它的导航罚款,也回到实际view.But如果我再次去增加视图控制器我的应用程序崩溃。这是显示的错误。从一个视图到另一个视图导致UINavigation崩溃,如何解决?

"Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing the same view controller instance more than once is not supported (<UIViewController: 0xc09e460>)' 
First throw call stack: 
(0x30da012 0x28b4e7e 0xb9c5b0 0xb9c098 0xa7f3f 0xab327 0x28c86b0 0x5fcfb 0x28c86b0 0x706035 0x305df3f 0x305d96f 0x3080734 0x307ff44 0x307fe1b 0x33127e3 0x3312668 0xaa265c 0x719d 0x2685) 
libc++abi.dylib: terminate called throwing an exception" 

我在代码中使用的方法操作是

- (void) move { 
    [self.navigationController pushViewController:addedviewController animated:YES]; 
} 

而且我加入了截图... enter image description here

+0

您使用回来什么样的策略? – Rajneesh071 2013-02-15 15:51:53

+0

只是断开你的IBOutlet连接并重新连接它 – Rajneesh071 2013-02-15 16:00:31

回答

2

您不能添加已经在堆栈上的viewcontroller的实例。为什么不在弹出控制器之前弹出控制器,直到获得添加的ViewController实例?

+0

可以用你的解释清楚。我不能得到你.. – NSUserDefault 2013-02-14 14:14:26

+0

从崩溃,记录很明显,你推动viewcontroller超过一个。在推动相同的视图控制器之前。您需要弹出视图控制器。看看这个http://developer.apple.com/library/ios/documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html#//apple_ref/occ/instm/UINavigationController/popViewControllerAnimated: – Shashank 2013-02-14 14:23:17

+0

也请解释我的用例更详细一点,因为我没有得到足够的从你的问题除了崩溃日志.. – Shashank 2013-02-14 14:25:13

0

如果你创建了另一个对象?

AddedviewControllerClass *addedviewControllerTemp = [[AddedviewControllerClass alloc] initWithNibName:@"yourXib.xib"]; 

[self.navigationController pushViewController:addedviewControllerTemp animated:YES]; 

[addedviewControllerTemp release] //if not ARC 
0

用于添加您ViewController

[self presentViewController:yourView animated:YES completion:nil]; 

要删除

[self dismissViewControllerAnimated:YES completion:nil]; 
相关问题