EA Rashel EA Rashel - 1 year ago 216
Objective-C Question

Using AlertView in xcode 8 with objective c

I am trying to show an alertview every time the user start the app.

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

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 emulator.The app runs but no alertview is showing. What i am doing wrong?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download