【发布时间】:2015-09-21 20:38:50
【问题描述】:
我正在使用 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>)
虽然我在应用程序中使用了UIAlertControllers,但在收到此错误之前没有使用或实例化。这仅在 iOS 9.0 下运行时发生。在 iOS 8.4 下运行不会产生错误。在所有情况下,应用似乎都可以正常运行,并且导航似乎可以正常工作。
我怀疑该错误具有误导性,但我该如何解决这个问题?
根据@Nick,这里是使用的 dealloc 方法:
- (void)deregisterNotificationHandlers {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)dealloc {
[self deregisterNotificationHandlers];
}
【问题讨论】:
-
我强烈怀疑您在某处使用 UIAlertController 并且没有意识到并且不打算这样做。在你呈现 UIAlertControllers 的地方设置断点,看看会发生什么
-
我在 + [UIAlertController alertControllerWithTitle:message:preferredStyle:] 上设置了一个断点,但没有。后来我确实创建了一个警报,断点确实起作用了。
-
您是否在任何地方覆盖
dealloc?你能发布更多代码吗? -
许多类都有一个 dealloc 方法来从通知中注销。我会在上面添加。
-
完全跑题了,但是...如果您的所有方法
-deregisterNotificationHandlers所做的只是调用+[NSNotificationCenter removeObserver:],也许您可以直接在-dealloc中执行此操作并删除多余的方法...
标签: ios swift xcode xcode7 mapbox-gl