iOS8.0之后,苹果公司推出了最新的UIAlertController用来代替UIActionSheet 和UIAlertView.
---UIActionSheet---
UIAlertController*alertController = [UIAlertControlleralertControllerWithTitle:@"保存或删除数据"message:@"删除数据将不可恢复"preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction*cancelAction = [UIAlertActionactionWithTitle:@"取消"style:UIAlertActionStyleCancelhandler:^(UIAlertAction*action) {
NSLog(@"取消!!!");//点击方法转移到了这里
}];
UIAlertAction*deleteAction = [UIAlertActionactionWithTitle:@"删除"style:UIAlertActionStyleDestructivehandler:^(UIAlertAction*action) {
NSLog(@"删除!!!");
}];
UIAlertAction*archiveAction = [UIAlertActionactionWithTitle:@"保存"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction*action) {
NSLog(@"保存!!!");
}];
[alertControlleraddAction:cancelAction];
[alertControlleraddAction:deleteAction];
[alertControlleraddAction:archiveAction];
[viewController presentViewController:alertController animated:YES completion:nil];
---UIAlertView---
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"A Short Title Is Best"message:@"A message should be a short, complete sentence."preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAlter = [UIAlertAction actionWithTitle:@"Cancel"style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
NSLog(@"The \"Okay/Cancel\" alert's cancel action occured.");
}];
UIAlertAction *otherAlter = [UIAlertAction actionWithTitle:@"OK"style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSLog(@"The \"Okay/Cancel\" alert's other action occured.");
}];
// Add the actions.
[alert addAction:cancelAlter];
[alert addAction:otherAlter];
[viewController presentViewController:alert animated:YES completion:nil];