Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to use UIAlertController for iOS8 and above.

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 293
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: