ios - 试图在释放时加载 View Controller 的 View ... UIAlertController

标签 ios swift xcode xcode7 mapbox-gl

我正在使用 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() 中声明了变量,但还没有使用它,它完全没有用类内部的函数作为变量。通过删除解决问题。因此,如果您没有使用它或在类变量中定义来自 UIAlertViewUIAlertViewController 的警报,请检查您的类!

关于ios - 试图在释放时加载 View Controller 的 View ... UIAlertController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32704169/

相关文章:

ios - 向 UITableViewCell : storyboard vs code 添加一个开关

iphone - iOS4如何重启 View Controller

ios - 在 WKInterfaceTable 的选择行上将数据传输到 Iphone

ios - 我们为什么要使用use_frameworks!在 CocoaPods 中?

python - 难以将 Python3 获取 hotp/totp token 代码转换为 Swift3

ios - Swift - 将 nil 核心数据字符串转换为可选值

swift - 为什么 nil 合并运算符包装一个隐式展开的默认值?

swift - NSKeyedUnarchiver解码ObjectForKey : cannot decode object of class AMPathPopUpButton for key NS.对象

c++ - 用于 iOS 的 leptonica 1.69 交叉编译(armv7、armv7s 和 arm64)

iphone - 带有移动临时证书的 .ipa 文件