popoverviewController crash on iPhone, works on iP

2019-02-28 21:34发布

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!

2条回答
三岁会撩人
2楼-- · 2019-02-28 22:05

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.

查看更多
欢心
3楼-- · 2019-02-28 22:12

Because UIPopoverController is only available on the iPad.

查看更多
登录 后发表回答