xcode iOS5 iPad UIPopoverController initWithContentViewController NSGenericException

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7766051/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 22:07:37  来源:igfitidea点击:

iOS5 iPad UIPopoverController initWithContentViewController NSGenericException

xcodeipadsdkios5

提问by Genar

The following code:

以下代码:

listViewPopoverControllerOL = [[UIPopoverController alloc] initWithContentViewController:myBranchesListViewPage];

produces the following crash in iPad2 with iOS5. As a comment I have to notice that the same code works perfectly in iOS4.3.

使用 iOS5 在 iPad2 中产生以下崩溃。作为评论,我必须注意到相同的代码在 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

Where "myBranchesListViewPage" is defined as:

其中“myBranchesListViewPage”定义为:

MyBranchesListView_iPad* myBranchesListViewPage

and "MyBranchesListViewPage" is defined as:

和“MyBranchesListViewPage”定义为:

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

I have no idea why I have this problem in iOS5 (Xcode 4.2) but not with iOS4.3 (Xcode 4.1)

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

Thanks in advance

提前致谢

回答by Jeff

I had this same issue. In my case I was doing the following:

我有同样的问题。就我而言,我正在执行以下操作:

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];

To solve this, I just changed to pass in the navigationController to init on UIPopoverController instead of the popupController:

为了解决这个问题,我只是改变了传入 navigationController 来初始化 UIPopoverController 而不是 popupController:

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

Not adding a navigation controller to the popupController at all also fixed it, but then you obviously don't have a navigation controller in the popup.

根本不向 popupController 添加导航控制器也修复了它,但是显然弹出窗口中没有导航控制器。

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

回答by Jacco

I had the same problem. I thought that having the ContentViewController as RootViewController of the NavigationController was enough, but, in my case, this was not true.

我有同样的问题。我认为将 ContentViewController 作为 NavigationController 的 RootViewController 就足够了,但就我而言,这不是真的。

My application windowhas an TabBarController as RootViewController, making this one the ContentViewController, fixed my problem.

我的应用程序窗口有一个 TabBarController 作为 RootViewController,使这个成为 ContentViewController,解决了我的问题。

My guess would be that you have to take the RootViewController of the window in your ApplicationDelegate, assign this to a variable and use this as your ContentViewController. You can simply use it by accessing [UIApplication sharedApplication].delegate.

我的猜测是您必须在 ApplicationDelegate 中获取窗口的 RootViewController,将其分配给一个变量并将其用作您的 ContentViewController。您可以通过访问 [UIApplication sharedApplication].delegate 来简单地使用它。

Regards,

问候,

Jacco

雅科