EXC_BAD_ACCESS on UIAlertController code = 1

I have a view controller from where I start UIAlertControllerwhen I click a button. Below is my code:

- (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];

}

But my application crashes giving EXC_BAD_ACCESS. enter image description here

After many attempts, I finally changed

[self presentViewController:alertController animated:YES completion:nil];

to

[self presentViewController:alertController animated:NO completion:nil];

in the above code and it started working.

So my question is, why is the transfer animated as YES giving this error?

It is also interesting to note that if I reset my entire emulator and run the application with an animated YES, then it works for the first few starts. After several runs of X, it starts to crash.

+4
source share

Source: https://habr.com/ru/post/1685752/


All Articles