Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • UIAlertController in iOS

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 343
    Comment on it

    For iOS 8 and above Apple have introduced UIAlertController to present action Sheet and alerts. In order to present alert set preferredStyle to UIAlertControllerStyleAlert and for actionSheet preferredStyle to UIAlertControllerStyleActionSheet of your UIAlertController.

    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"title" message:@"message" preferredStyle:UIAlertControllerStyleAlert];
    //change preferredStyle  to UIAlertControllerStyleActionSheet in case of action Sheet

    To add button and their action:

    UIAlertAction* okbttn = [UIAlertAction actionWithTitle:@OK style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
            NSLog(@" ok clicked);
          }];
    [alertController addAction: okbttn];
    UIAlertAction* cancelbttn = [UIAlertAction actionWithTitle:@cancel style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
          [alertController dismissViewControllerAnimated:YES completion:nil]; 
       }]; 
    [alertController addAction: cancelbttn];
    

    to add textField in alertView :

    [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
      textField.placeholder=@"name";
    }];
    
    [self presentViewController:alertController animated:YES completion:nil];

 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: