iOS8에서 UIAlertView deprecated 되었음

2016. 4. 18. 16:35아이폰 개발

그동안 잘써왔던 UIAlertView가 iOS에서 deprecated 되었다.

UIAlertController와 UIAlertAction을 이용하여 구현하도록 변경되었으니 참고하자.


//Step 1: Create a UIAlertController
    UIAlertController *myAlertController = [UIAlertController alertControllerWithTitle:@"MyTitle"
                                                              message: @"MyMessage"
                                                              preferredStyle:UIAlertControllerStyleAlert                   ];

    //Step 2: Create a UIAlertAction that can be added to the alert
    UIAlertAction* ok = [UIAlertAction
                         actionWithTitle:@"OK"
                         style:UIAlertActionStyleDefault
                         handler:^(UIAlertAction * action)
                         {
                             //Do some thing here, eg dismiss the alertwindow
                             [myAlertController dismissViewControllerAnimated:YES completion:nil];

                         }];

    //Step 3: Add the UIAlertAction ok that we just created to our AlertController
    [myAlertController addAction: ok];

    //Step 4: Present the alert to the user
    [self presentViewController:myAlertController animated:YES completion:nil];

http://stackoverflow.com/questions/30933965/how-do-i-migrate-from-uialertview-deprecated-in-ios8