UIAlertView Deprecated in Xcode6.0

U

Hi All,

Everybody is curious about changes made by Apple in Xcode 6 and newly added functionalities, here is the one noticeable change which is nothing but UIAlertView and UIActionsheet is deprecated.
Now Apple has introduced a new class for replacement of those – UIAlertController. Let see how it can be used for displaying alertview :

UIAlertController *alertController = [UIAlertController
                              alertControllerWithTitle:@"Title"
                              message:@"Message"
                              preferredStyle:UIAlertControllerStyleAlert];

Buttons can be added by creating instance of the UIAlertAction 


UIAlertAction *cancelAction = [UIAlertAction 
            actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel method")
                      style:UIAlertActionStyleCancel
                    handler:^(UIAlertAction *action)
                    {
                      NSLog(@"Cancel button called");
                    }];

UIAlertAction *okAction = [UIAlertAction 
            actionWithTitle:NSLocalizedString(@"OK", @"OK method")
                      style:UIAlertActionStyleDefault
                    handler:^(UIAlertAction *action)
                    {
                      NSLog(@"OK button called");
                    }];

[alertController addAction:cancelAction];
[alertController addAction:okAction];

About the author

minakshi.bhosale
By minakshi.bhosale

Category