-
Notifications
You must be signed in to change notification settings - Fork 149
Open
Description
/**
* 对于代码构建 UI 的项目一般在 didFinishLaunch 方法中初始化 window,
* 想在 swizzling 方法中 present alertController 需要自己先初始化 window 并提供一个 rootViewController
*/
- (void)presentAlertViewController:(UIAlertController *)alertController {
if (![self hasStoryboardInfo]) {
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.rootViewController = [[UIViewController alloc] init];
}
[self.window makeKeyAndVisible];
[self.window.rootViewController presentViewController:alertController animated:YES completion:nil];
}使用storyboard构建的window,在presentAlertViewController的时候 [self.window makeKeyAndVisible]就把window展示出来了,导致rootViewController被初始化,业务代码就被执行了,而且,如果是使用storyboard构建的window,我们无法掌控这个window什么时候被初始化,建议使用者手动初始化window
Metadata
Metadata
Assignees
Labels
No labels