Apple has deprecated UIAlertView in iOS 8 and above. Now they have introduce UIAlertController, below are the examples.
AlertView without buttons:-
UIAlertController * alert=   [UIAlertController
                                alertControllerWithTitle:@"Sample App"
                                message:@"Welcome!!!"
                                preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:alert animated:YES completion:nil];
AlertView with buttons and their actions:-
    UIAlertController * alert=   [UIAlertController
                                 alertControllerWithTitle:@"Info"
                                 message:@"You are using UIAlertController"
                                 preferredStyle:UIAlertControllerStyleAlert];
   UIAlertAction* okBtn = [UIAlertAction
                        actionWithTitle:@"OK"
                        style:UIAlertActionStyleDefault
                        handler:^(UIAlertAction * action)
                        {
                            [alert dismissViewControllerAnimated:YES completion:nil];
                        }];
   UIAlertAction* cancelBtn= [UIAlertAction
                            actionWithTitle:@"Cancel"
                           style:UIAlertActionStyleDefault
                           handler:^(UIAlertAction * action)
                           {
                               [alert dismissViewControllerAnimated:YES completion:nil];
                           }];
   [alert addAction:okBtn];
   [alert addAction:cancelBtn];
   [self presentViewController:alert animated:YES completion:nil];
Happy Coding!!!
                       
                    
0 Comment(s)