Scenario: when the mode jumps, the prompt box uialertcontroller will not appear when it is written in viewdidload, and the following warning will appear:
Solution:
You can put this code into viewdidappearance, but I think it’s better for you to get the current controller
UIAlertController *alert = [UIAlertController alertControllerWithTitle:"Warning" message:@"sdsdfsdf" preferredStyle: UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil]];
UIViewController *topRootViewController = [[UIApplication sharedApplication] keyWindow].rootViewController;
// loop
while (topRootViewController.presentedViewController)
{
topRootViewController = topRootViewController.presentedViewController;
}
// Then the present operation is performed
[topRootViewController presentViewController:alert animated:true completion:nil];
This will do
Similar Posts:
- whose view is not in the window hierarchy!
- [How to Solve] Xcode:No such module SwiftyJSON
- How to Solve JSLint Error: Don’t make functions within a loop
- Block Wild Pointer crash: Thread 1:EXC_BAD_ACCESS(code=1,address=0x10)
- iOS Presenting view controllers on detached view controllers is discouraged
- [Solved] org.springframework.web.servlet.PageNotFound noHandlerFound Warning: No mapping found for HTTP request w
- [Solved] Controller Error: Error:-81024 LR_VUG:The ‘QTWeb’ type is not supported on win32 platforms
- [Solved] The cause of the wrong prompt instruction [ng: areq] in angular
- Trouble Connecting to sql server Login failed. “The login is from an untrusted domain and cannot be used with Windows authentication”
- loaded some nib but the view outlet was not set