我有一个登录界面,我在一个地方分配,而在另一个解雇,并在解雇,其dealloc
方法不会被调用和伊娃拿着登录屏幕,即使在我被解雇的代码被分配零后仍然具有价值。如何取消分配我的视图控制器?
这里是我的配置
-(void)loginUser
{
loginScreen = [[LoginScreen alloc] initWithNibName:@"LoginScreen" bundle:nil];
[self.tabBarController addChildViewController:loginScreen];
[self.tabBarController.view addSubview:loginScreen.view];
[loginScreen didMoveToParentViewController:self.tabBarController];
[self.tabBarController.view bringSubviewToFront:loginScreen.view];
}
这是我的解雇和重新分配的另一种方法(不取消分配)
[UIView animateWithDuration:0.4 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
loginScreen.view.frame = CGRectOffset(frame, -1024, 0);
}
completion:^(BOOL finished) {
// Remove the loginScreen
[loginScreen willMoveToParentViewController:nil];
[loginScreen.view removeFromSuperview];
[loginScreen removeFromParentViewController];
[loginScreen cleanupBeforeDealloc];
loginScreen = nil;
}];
我有一些代码,监听键盘的通知在LoginScreen里面,但是我在下面添加了一个方法来清理它,并且我试着在上面的解雇代码中调用它,但是仍然没有解决它。 GRRRR。
-(void)cleanupBeforeDealloc
{
[self deregisterFromKeyboardNotifications];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
你有什么让你的loginScreen内的强引用本身。如果你想让我们知道它是什么,请添加你的loginScreen代码。你不会手动释放你的viewControllers,ARC会为你处理。 – 2017-02-28 21:06:49
@Sneak。不,我很抱歉,我没有任何东西保留有力的参考。我用正则表达式'loginscreen'搜索了我的整个项目,代码中的每个实例/用法都在上面两种方法中进行了说明。我打算发布截图,但是stackoverflow/imagur目前无法接受图片上传。 –
没错。如果'dealloc'没有被调用时,你有一个保留周期。您可以使用“泄漏”工具来追踪它。 – matt