Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Using UIAlertController instead of UIAlertView (Deprecated) in iOS

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 2.00k
    Comment on it

    Hi guys,

    As we all know that from iOS8 Apple has provided a new UIAlertController class which you can use instead of UIAlertView which is now deprecated. So today i'll demonstrate, how to use UIAlertController for displaying an alert in iOS. Here are two simple steps that are declaration & calling it easy to use.

    Here we are defining alert controller along with the message that it will display & the "OK" button which we use to remove alert once popped.

    -(void)alertAction:(NSString *)title message:(NSString *)message {
        
        UIAlertController * alert = [UIAlertController
                                     alertControllerWithTitle:title
                                     message:message
                                     preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction* ok = [UIAlertAction
                             actionWithTitle:@"OK"
                             style:UIAlertActionStyleDefault
                             handler:^(UIAlertAction * action)
                             {
                                 [alert dismissViewControllerAnimated:YES completion:nil];
                             }];
        
        [alert addAction:ok];
        [self presentViewController:alert animated:YES completion:nil];
        
    }

     

    And now all we have to do is call the above function wherever u need the alert popup as-

    [self alertAction:@"Your message that you Want to display at the title of alert we generally use app Name" message:@"Actual message that you want to notify the user"];

    Thanks for reading, hope it helps.

 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: