popoverviewController crash on iPhone, works on iPad

↘锁芯ラ 提交于 2019-12-02 12:59:20

问题


a noob question here:

any ideas why this code:

UIViewController* popoverviewController = [[UIViewController alloc]init];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];

[webViewnetwork loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"webView" ofType:@"html"]isDirectory:NO]]];
[popoverView addSubview:webViewnetwork];

popoverviewController.view = popoverView;
popoverviewController.contentSizeForViewInPopover = CGSizeMake (100, 100);

self.popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverviewController];
[self.popoverController presentPopoverFromRect:CGRectMake(0, 0, 1, 1) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

would work fine on iPad, but crash on iPhone ? I'm trying to do the same thing as in my iPad version, which is adding a subview with an html formatted text. It crashes (program received signal: SIGABRT) on the 7th line (initWithContentViewController)

thank you!


回答1:


Because UIPopoverController is only available on the iPad.




回答2:


You cannot use a UIPopoverController with iPhone. U will need to detect which device idiom u are using and present the appropriate viewController type at runtime.

The project here provides some examples. The basic gist of it is the following:

 if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
     /* use iPhone related viewController via either presentModal or via UIViewController containment */
 }else{
     /* Using an iPad use a popoverController */
 }

Good Luck.



来源:https://stackoverflow.com/questions/8391176/popoverviewcontroller-crash-on-iphone-works-on-ipad

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!