美文网首页IOSiOS学习笔记IOS
UIAlertController基本应用

UIAlertController基本应用

作者: 大不不 | 来源:发表于2016-03-02 16:16 被阅读105次

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];

相关文章

网友评论

    本文标题:UIAlertController基本应用

    本文链接:https://www.haomeiwen.com/subject/ctyjkttx.html