0

我已经更新了 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];
4

1 回答 1

0

您呈现的实际上是一个操作表,它不等同于UIAlertView. 你应该改变preferredStyleUIAlertControllerStyleAlert改用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.

于 2014-09-22T14:55:15.290 回答