所以我刚开始使用Xcode并试图修复现有的应用程序。我遇到的麻烦是将HTML文件加载到模态窗口中。
这是我认为相关的代码:
-(void) loadScreen
{
[super loadScreen];
formView = [[ontracHazardsFormSheetViewController alloc] init];
[formView setModalPresentationStyle:UIModalPresentationFormSheet];
formView.urlToLoad = [self.urlToLoadstringByAppendingString:@"/redzone"];
formView.cookieValue = self.cookieValue;
formView.dataObject = self.dataObject;
formView.htmlString = self.redzoneHTMLString;
[formView loadScreen];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
NSMutableArray *array = [self.navigationItem.rightBarButtonItems mutableCopy];
UIBarButtonItem *redZoneButton = [[UIBarButtonItem alloc] initWithTitle:@"Red Zones" style:UIBarButtonItemStylePlain target:self action:@selector(displayRedZones:)];
redZoneButton.tintColor = [UIColor redColor];
[array addObject:redZoneButton];
self.navigationItem.rightBarButtonItems = array;
}
-(IBAction)displayRedZones:(id)sender
{
NSLog(@"red zones");
[self presentViewController:formView animated:NO completion:nil];
//ontracWebViewController
}
我有一个启动displayRedZones的按钮,当我使用它时会产生以下崩溃报告:
2016-03-30 14:05:55.539 eCoss[3680:1292033] *** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '-[_UIAlertControllerActionSheetRegularPresentationController _defaultAnimationController]: unrecognized selector sent to instance 0x15710d10'
*** First throw call stack:
(0x2265c10b 0x21e02e17 0x22661925 0x2265f559 0x2258fc08 0x26b05e03 0x267a7651 0x26b05d69 0x2689a979 0x268c631d 0x268c50b1 0x22e697bd 0x2261fe1f 0x2261fa51 0x2261d89d 0x22570bf9 0x225709e5 0x237bcac9 0x26800ba1 0xd1ac1 0x2221f873)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
当应用程序崩溃时,Xcode也会显示:
就像我说的那样,我完全不习惯使用Xcode和IOS开发,所以如果我没有包含一些关键的内容请原谅我并让我知道。
感谢
答案 0 :(得分:1)
使用以下代码:
适用于iPhone:
[self presentViewController: formView animated:YES completion:nil];
适用于iPad:
UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:formView];
[popup presentPopoverFromRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
像,
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
[self presentViewController:formView animated:YES completion:nil];
}
else {
// Change Rect to position Popover
UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:formView];
[popup presentPopoverFromRect:CGRectMakeCGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
注意:根据需求进行修改。