0

How to change this obj c code that suits with iOS 9 above ? i have this error when i updating X Code into 8.2.1 . The code as below

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSString *title = [alertView buttonTitleAtIndex:buttonIndex];

    if([title isEqualToString:@"Continue"]){
        NSLog(@"Continue...");
        [self performSegueWithIdentifier:@"createlogin" sender:self];
    }
}

The error:

UIAlertView is deprecated : first deprecated in iOS 9.0 - UIAlertView is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert instead

Thanks.

Ronak Chaniyara
  • 5,335
  • 3
  • 24
  • 51
Jamilah
  • 165
  • 5
  • 21
  • 2
    Possible duplicate of [UIAlertView first deprecated IOS 9](http://stackoverflow.com/questions/32690086/uialertview-first-deprecated-ios-9) – GeneCode Jan 03 '17 at 09:12

3 Answers3

2
 UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"Add Title" message:@"Add Message" preferredStyle:UIAlertControllerStyleAlert];
     UIAlertAction * actionOK = [UIAlertAction actionWithTitle:@"Button Title" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                        //Here Add Your Action
                    }];
     UIAlertAction * actionCANCEL = [UIAlertAction actionWithTitle:@"Second Button Title" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                        //Add Another Action
                    }];


               [alert addAction:actionOK];
             [alert addAction:actionCANCEL];

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

Use this Method if any need ask me and for more Information use this Link http://useyourloaf.com/blog/uialertcontroller-changes-in-ios-8/

Gurinder Batth
  • 655
  • 9
  • 18
0

Use this code

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction * continueButton = [UIAlertAction actionWithTitle:@"Continue" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){
      [self performSegueWithIdentifier:@"createlogin" sender:self];
  }];
 UIAlertAction * cancelButton = [UIAlertAction actionWithTitle:@"cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){

  }];
[alert addAction:continueButton];
[alert addAction:cancelButton];
[self presentViewController:alert animated:YES completion:nil];
0

try this:

UIAlertController *controller = [UIAlertController alertControllerWithTitle:@"Your message title"
                                                                                message:@"Enter your message here."
                                                                         preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action)
 {
     NSLog(@"Ok Action");
 }];
UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Skip" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action)
 {
     NSLog(@"Cancel Action");
}];

[controller addAction:okAction];
[controller addAction:cancelAction];
[self presentViewController:alertController animated:YES completion:nil];
amit_donga
  • 224
  • 1
  • 9