EA Rashel EA Rashel - 1 month ago 18
Objective-C Question

Using UIAlertController in Xcode 8 with Objective-C

I am trying to show a

every time the user start the app.

- (void)viewDidLoad {
[super viewDidLoad];

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"My alert" message:@"This should be come when the app start" preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *yesButton = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
[self dismissViewControllerAnimated:YES completion:nil];

[alert addAction:yesButton];
[self presentViewController:alert animated:YES completion:nil];

But this is not working. I run the app in Xcode simulator. The app runs but no alertview is showing. What am I doing wrong?


Try opening the UIAlertController in the viewDidAppear: delegate instead. Alternatively, you could show it as part of your AppDelegate method didFinishLaunchingWithOptions: to make it more view-controller independent.