我正在使用 Xcode 7.0 的发布版本进行构建。没有故事板,只有 nib 文件。
我有一个UINavigationController
由应用程序委托创建的,并使用视图控制器对其进行初始化。
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *viewController = [[TGMainViewController alloc] initWithNibName:nil bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
self.navigationController.navigationBar.hidden = YES;
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
使用以下命令导航到新视图后:
TGRoutePreparationViewController *viewController = [[TGRoutePreparationViewController alloc] initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:viewController animated:YES];
然后返回使用:
[self.navigationController popViewControllerAnimated:YES];
我收到以下错误:
Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior (<UIAlertController: 0x7b29a600>)
虽然我UIAlertController
在应用程序中使用了 s,但在收到此错误之前没有使用或实例化。这仅在 iOS 9.0 下运行时发生。在 iOS 8.4 下运行不会产生错误。在所有情况下,该应用程序似乎都可以正常运行,并且导航似乎可以正常工作。
我怀疑该错误具有误导性,但我该如何解决这个问题?
根据@Nick,这是使用的 dealloc 方法:
- (void)deregisterNotificationHandlers {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)dealloc {
[self deregisterNotificationHandlers];
}