xcode – iOS5 iPad UIPopoverController initWithContentViewController NSGenericException

前端之家收集整理的这篇文章主要介绍了xcode – iOS5 iPad UIPopoverController initWithContentViewController NSGenericException前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
以下代码
listViewPopoverControllerOL = [[UIPopoverController alloc] initWithContentViewController:myBranchesListViewPage];

在iPad2与iOS5之间产生以下崩溃.作为评论,我必须注意到,相同的代码在iOS4.3中完美地工作.

*** Terminating app due to uncaught exception 'NSGenericException',reason: 'The content view controller argument must be the root of its associated view controller hierarchy.'
*** First throw call stack:(0x370cb8bf 0x35eaa1e5 0x370cb7b9 0x370cb7db 0x306f378d 0x306f0db9 0x5692d 0x567d1 0x37025435 0x303499eb 0x303499a7 0x30349985 0x303496f5 0x3034a02d 0x3034850f 0x30347f01 0x3032e4ed 0x3032dd2d 0x35bdfe13 0x3709f553 0x3709f4f5 0x3709e343 0x370214dd 0x370213a5 0x35bdefed 0x3035c743 0x2871 0x2830) terminate called throwing an exception

其中“myBranchesListViewPage”被定义为:

MyBranchesListView_iPad* myBranchesListViewPage

和“MyBranchesListViewPage”定义为:

MyBranchesListView_iPad : UIViewController<UITableViewDelegate,UITableViewDataSource,MyDetailParserDelegate,UISplitViewControllerDelegate>

我不知道为什么我在iOS5(Xcode 4.2)中有这个问题,但不是iOS4.3(Xcode 4.1)

提前致谢

解决方法

我有同样的问题.在我的情况下,我正在做以下事情:
MyViewController * popupController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
[popupController setDelegate:self];
UINavigationController *  navigationController = [[UINavigationController alloc] initWithRootViewController:popupController];
[navigationController setNavigationBarHidden:YES animated:NO ]; 

UIPopoverController* aPopover = [[UIPopoverController alloc]
                        initWithContentViewController:popupController];
[popupController release];

[navigationController release];

为了解决这个问题,我刚刚更改为在navControlController中传递给UIPopoverController而不是popupController的init:

UIPopoverController* aPopover = [[UIPopoverController alloc]
                initWithContentViewController:navigationController];

没有将导航控制器添加到popupController中也修复它,但是您显然在弹出窗口中没有导航控制器.

MyViewController * popupController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
[popupController setDelegate:self];
UIPopoverController* aPopover = [[UIPopoverController alloc]
                initWithContentViewController:popupController];
[popupController release];

猜你在找的iOS相关文章