Tôi muốn hiển thị thông báo cảnh báo từ viewDidLoad()
phương thức ViewController.m
thay vì phương thức viewDidAppear()
.Hiển thị thông báo cảnh báo từ viewDidLoad
Đây là mã của tôi:
- (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];
}
và tôi nhận được lỗi này:
Warning: Attempt to present
<UIAlertController: 0x7fbc58448960>
on<ViewController: 0x7fbc585a09d0>
whose view is not in the window hierarchy!
Bản sao có thể có của [chế độ xem không có trong hệ thống phân cấp cửa sổ] (http://stackoverflow.com/questions/11862883/whose-view-is-not-in-the-window-hierarchy) – Woodstock
@Woodstock câu hỏi của tôi khác ... –