如何在 iOS 8 中使用 UIAlertView?
How to use UIAlertView with iOS 8?
自 iOS8 发布以来我一直在使用 AlertView,但在 iOS8 发布后,UIAlertView 被 UIAlertViewController 取代。那么如何将它用作 UIAlertView。
AlertView 在 Swift 在 ios8
var alert = UIAlertController(title: "Alert", message: "Message", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
if ([UIAlertController class])
{
// use UIAlertController
UIAlertController *alert= [UIAlertController
alertControllerWithTitle:@"Enter Folder Name"
message:@"Keep it short and sweet"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action){
//Do Some action here
}];
UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
NSLog(@"cancel btn");
[alert dismissViewControllerAnimated:YES completion:nil];
}];
[alert addAction:ok];
[alert addAction:cancel];
[self presentViewController:alert animated:YES completion:nil];
使用此代码
UIAlertController * myAlert= [UIAlertController
alertControllerWithTitle:@"My Alert"
message:@"put a message here"
preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:MyAlert animated:YES completion:nil];
自 iOS8 发布以来我一直在使用 AlertView,但在 iOS8 发布后,UIAlertView 被 UIAlertViewController 取代。那么如何将它用作 UIAlertView。
AlertView 在 Swift 在 ios8
var alert = UIAlertController(title: "Alert", message: "Message", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
if ([UIAlertController class])
{
// use UIAlertController
UIAlertController *alert= [UIAlertController
alertControllerWithTitle:@"Enter Folder Name"
message:@"Keep it short and sweet"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action){
//Do Some action here
}];
UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
NSLog(@"cancel btn");
[alert dismissViewControllerAnimated:YES completion:nil];
}];
[alert addAction:ok];
[alert addAction:cancel];
[self presentViewController:alert animated:YES completion:nil];
使用此代码
UIAlertController * myAlert= [UIAlertController
alertControllerWithTitle:@"My Alert"
message:@"put a message here"
preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:MyAlert animated:YES completion:nil];