为什么UIAlertController在iOS7中得到零值,而需要提供但是在iOS8中工作是好的,我可以知道这是因为iOS7不支持UIAlertController类吗?
UIAlertController *view=[UIAlertController
alertControllerWithTitle:@"Hello"
message:nil
preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:view animated:NO completion:nil];发布于 2014-11-03 08:10:14
这些类仅在iOS8和更高版本中可用。见类引用
发布于 2014-11-03 09:08:53
为了在AlertView和较低版本中显示iOS 8,可以使用以下代码:
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);
}发布于 2015-02-02 11:21:31
您可能正在使用比iOS 8更少的os版本。
如果您使用Xcode 6编译代码,并使用iOS版本< 8.0的设备,那么您将面临这个问题。我建议如下
- (void)showXYZAlert
{
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0"))
{
// Handle UIAlertController
[self showXYZAlertController];
}
else
{
// Handle UIAlertView
[self showXYZAlertControllerView];
}
}https://stackoverflow.com/questions/26710018
复制相似问题