我试图在iOS 9中检查我的示例应用程序的UIAlertController,并在运行它时发现了控制台中的警告。我正在使用Xcode 7和Objective C.试图在其视图不在窗口层次结构中的UIViewController上呈现UIAlertController
请在控制台中找到以下警告消息。
Warning: Attempt to present < UIAlertController: 0x7fb1bb5be040 > on < ViewController: 0x7fb1bb5aef30 > whose view is not in the window hierarchy!
请找到下面的代码以获取更多信息。
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"My Alert"
message:@"This is an alert."
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {}];
[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];
你在哪里调用这段代码? –
你在viewDidload上调用了这个吗? –
@ Mr.T:是的,我打电话给viewDidLoad。 –