加载模式窗口时应用程序崩溃
Posted
技术标签:
【中文标题】加载模式窗口时应用程序崩溃【英文标题】:App crashes on loading modal window 【发布时间】:2016-03-30 13:17:34 【问题描述】:所以我是使用 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 开发完全不熟悉,所以如果我没有包含重要的内容,请原谅我并告诉我。
谢谢
【问题讨论】:
Xcode 崩溃了,还是您的应用程序崩溃了? 应用程序,Xcode 很好 那么请修正您的问题的标题。 该死的问题很糟糕:/ 谢谢,没想到 【参考方案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];
注意:根据需求进行修改。
【讨论】:
以上是关于加载模式窗口时应用程序崩溃的主要内容,如果未能解决你的问题,请参考以下文章