【发布时间】:2016-01-09 10:10:02
【问题描述】:
我想显示来自ViewController.m 的viewDidLoad() 方法而不是viewDidAppear() 方法的警报消息。
这是我的代码:
- (void)viewDidLoad {
[super viewDidLoad];
//A SIMPLE ALERT DIALOG
UIAlertController *alert = [UIAlertController
alertControllerWithTitle:@"My Title"
message:@"Enter User Credentials"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction
actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel action")
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *action)
{
NSLog(@"Cancel action");
}];
UIAlertAction *okAction = [UIAlertAction
actionWithTitle:NSLocalizedString(@"OK", @"OK action")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action)
{
NSLog(@"OK action");
}];
[alert addAction:cancelAction];
[alert addAction:okAction];
[self presentViewController:alert animated:YES completion:nil];
}
我收到此错误:
警告:尝试在视图不在窗口层次结构中的
<ViewController: 0x7fbc585a09d0>上显示<UIAlertController: 0x7fbc58448960>!
【问题讨论】:
-
@Woodstock 我的问题不同...
标签: ios objective-c xcode uialertview