我正在使用 Xcode 7.0 的发行版进行构建。没有 Storyboard,只有 nib 文件。
我有一个由应用程序委托(delegate)创建的 UINavigationController
并使用 View Controller 对其进行初始化。
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];
导航到新 View 后使用:
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
,但在收到此错误之前没有使用或实例化任何一个。只有在 iOS 9.0 下运行时才会发生这种情况。在 iOS 8.4 下运行不会产生错误。在所有情况下,该应用似乎都正常运行,并且导航似乎正常工作。
我怀疑该错误具有误导性,但我该如何解决?
Per @Nick,这是正在使用的 dealloc 方法:
- (void)deregisterNotificationHandlers {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)dealloc {
[self deregisterNotificationHandlers];
}
最佳答案
我的 UIViewController
也有同样的问题,我只是在我的类 let alert = UIAlertView()
中声明了变量,但还没有使用它,它完全没有用类内部的函数作为变量。通过删除解决问题。因此,如果您没有使用它或在类变量中定义来自 UIAlertView
或 UIAlertViewController
的警报,请检查您的类!
关于ios - 试图在释放时加载 View Controller 的 View ... UIAlertController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32704169/