我有一个视图控制器,我在点击按钮时启动UIAlertController
。以下是我的代码:
- (IBAction)playOnlineURL:(UIButton *)sender {
[self launchPlayURLAlert];
}
- (void) launchPlayURLAlert{
NSString *defaultURLString = @“MY URL”;
UIAlertController * alertController = [UIAlertController alertControllerWithTitle: @"Play Online URL"
message: @"Enter the URL"
preferredStyle:UIAlertControllerStyleAlert];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"Enter URL";
textField.text = defaultURLString;
textField.textColor = [UIColor blueColor];
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.borderStyle = UITextBorderStyleRoundedRect;
}];
[alertController addAction:[UIAlertAction actionWithTitle:@"Play" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSURL *url = [[NSURL alloc] initWithString:[[alertController textFields] firstObject].text];
VideoPlayerVC *videoController = [[VideoPlayerVC alloc] initWithNibName:@"VideoPlayerVC"
bundle:nil
url:url];
[self presentViewController:videoController animated:YES completion:nil];
}]];
[alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];
[self presentViewController:alertController animated:YES completion:nil];
}
但是,我的应用程序崩溃了,提供了EXC_BAD_ACCESS。
在尝试了很多事情之后,我终于改变了
[self presentViewController:alertController animated:YES completion:nil];
到
[self presentViewController:alertController animated:NO completion:nil];
在上面的代码中它开始工作。
所以,我的问题是为什么将动画为YES 给出该崩溃?
另外,一个有趣的注意事项是,如果我重置整个模拟器并以动画为YES运行应用程序,那么它将在前几次运行时运行。经过一些X运行后,它开始崩溃。