2014年9月26日 星期五

[iOS] iOS 8 用 UIAlertController 來取代原本的 UIAlertView & UIActionSheet

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@“title" message:@“message" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@“cancel"
                                                                      style:UIAlertActionStyleCancel
                                                                    handler:^(UIAlertAction * action)
{
    [alert dismissViewControllerAnimated:YES completion:nil];
}];

UIAlertAction *okAction = [UIAlertAction actionWithTitle:@“ok"
                                                               style:UIAlertActionStyleDefault
                                                             handler:^(UIAlertAction * action)
{
    [alert dismissViewControllerAnimated:YES completion:nil];
}];
[alert addAction:cancelAction];
[alert addAction:okAction];
[self presentViewController:alert animated:YES completion:nil];

以下連結有更詳細的介紹:
http://useyourloaf.com/blog/2014/09/05/uialertcontroller-changes-in-ios-8.html

沒有留言:

張貼留言