0

I want to display an alert. But as uialertView is deprecated for iOS 8, what can I do to display the alert for both kind of OS?

Anton K
  • 4,658
  • 2
  • 47
  • 60

1 Answers1

1

Try this code snippet to display the alert view in iOS8.This will definitely work.


- (IBAction)btn1Clicked:(UIButton *)sender {

// Alert style
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"ALERT!" message:@"What will you do?" preferredStyle:UIAlertControllerStyleAlert];

__weak ViewController *wself = self;

// Make choices for the user using alert actions.
**UIAlertAction** *doSomethingAction = [UIAlertAction actionWithTitle:@"I'm doing something" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
    __strong ViewController *sself = wself;
    sself.alertResponseLabel.text = @"You did something!";
}];

 UIAlertAction *doNothingAction = [UIAlertAction actionWithTitle:@"I'm totally ignoring this" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
    __strong ViewController *sself = wself;
    sself.alertResponseLabel.text = @"OK, just ignore me...";
}];

// Add actions to the controller so they will appear
[**alert addAction:doSomethingAction];
[alert addAction:doNothingAction];**
 alert.view.tintColor = [UIColor blackColor];
**[self presentViewController:alert animated:YES completion:nil];**  }
Alen Alexander
  • 725
  • 6
  • 22