UIAlertController的标题没有出现在iOS 8.0中

时间:2014-09-22 14:38:14

标签: ios uialertcontroller

我已针对XCode 6.0.1,iOS 8.0进行了更新,之后使用UIAlertController而不是UIAlertView,但UIAlertController的标题未显示。 有关参考,请参阅代码:

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"AlertView"    message:@"Please Click" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) 
{
}];

UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) 
{
    [alert dismissViewControllerAnimated:YES completion:nil];
}];

[alert addAction:defaultAction];
[alert addAction:cancel];
[self presentViewController:alert animated:YES completion:nil];

1 个答案:

答案 0 :(得分:0)

您所呈现的内容实际上是操作表,与UIAlertView不同。您应该更改preferredStyle,使用 UIAlertControllerStyleAlert 代替 UIAlertControllerStyleActionSheet

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"AlertView" message:@"Please Click" preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:alert animated:YES completion:nil];

现在,按钮在哪里?您可以添加例如(在 presentViewController 之前):

[alert addAction:[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:nil]];

然后创建您的操作以实施handler