在取消分配时尝试加载视图控制器的视图... UIAlertController

pic*_*ano 38 xcode ios swift mapbox-gl xcode7

我正在使用Xcode 7.0的发布版本构建.没有故事板,只有nib文件.

我有一个UINavigationController由app delegate创建并使用视图控制器初始化它.

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];
Run Code Online (Sandbox Code Playgroud)

使用以下方法导航到新视图后:

TGRoutePreparationViewController *viewController = [[TGRoutePreparationViewController alloc] initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:viewController animated:YES];
Run Code Online (Sandbox Code Playgroud)

然后回去使用:

[self.navigationController popViewControllerAnimated:YES];
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior (<UIAlertController: 0x7b29a600>)
Run Code Online (Sandbox Code Playgroud)

虽然我UIAlertController在应用程序中使用s,但在收到此错误之前没有使用或实例化.这仅在iOS 9.0下运行时才会发生.在iOS 8.4下运行不会产生错误.在所有情况下,应用程序似乎正常运行,导航似乎正在工作.

我怀疑这个错误是误导性的,但我怎么能解决这个问题呢?

Per @Nick,这是使用的dealloc方法:

- (void)deregisterNotificationHandlers {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)dealloc {
    [self deregisterNotificationHandlers];
}
Run Code Online (Sandbox Code Playgroud)

Aao*_*oIi 47

我有同样的问题,我UIViewController只在我的类中声明变量let alert = UIAlertView()而不使用它,它是在类中作为变量的所有函数.通过删除解决问题.所以请在你的类检查是否已经从定义的警报UIAlertViewUIAlertViewController那样的不使用它或类变量!


pic*_*ano 6

我终于能够将它跟踪到UIActionSheet第三方库Mapbox GL中的类变量.

我向开发团队提出了一个问题:https://github.com/mapbox/mapbox-gl-native/issues/2475

部分信用(以及向上投票和赏金)给@Aaoli提及有UIAlertView一个类变量.


Pho*_*int 5

我们遇到了同样的问题UIAlertController.

let alert = UIAlertController(title: "", message: "", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: {(action : UIAlertAction!) in
                //some actions
                              } ))
Run Code Online (Sandbox Code Playgroud)

我忘记添加以下行.下面的线解决了这个问题.

self.presentViewController(alert, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)