爲了你可以使用下面的代碼都iOS 8
和更低的版本顯示AlertView
:
if ([self isiOS8OrAbove]) {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title
message:message
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
[self.navigationController popViewControllerAnimated:YES];
}];
[alertController addAction:okAction];
[self presentViewController:alertController animated:YES completion:nil];
} else {
UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alertView show];
[self.navigationController popViewControllerAnimated:YES];
}
- (BOOL)isiOS8OrAbove {
NSComparisonResult order = [[UIDevice currentDevice].systemVersion compare: @"8.0"
options: NSNumericSearch];
return (order == NSOrderedSame || order == NSOrderedDescending);
}
UIAlertController是爲iOS 8引入的。它不適用於iOS7。對於iOS7,您應該使用UIAlertView。 – Sreejith 2014-11-03 08:09:06
http://stackoverflow.com/questions/25111011/uialertview-uialertcontroller-ios-7-and-ios-8-compatibility – Sreejith 2014-11-03 08:09:24
我已經創建了一個可以既可以使用一個簡單的包裝類。它模仿UIAlertController。 https://github.com/Reggian/RAAlertController – Reggian 2015-01-30 14:49:13