首先,我已经阅读了很多关于 SO 的答案,但我似乎仍然无法解决这个问题。
在我的 appDelegate 中,如果用户未登录,我会显示窗口的 rootViewController 中的 WelcomeViewController
,它是 MMDrawerController 的一个实例:
WelcomeViewController welcome = [[WelcomeViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:welcome];
[self.window.rootViewController presentViewController:nav animated:false completion:nil];
// NSLog(@"self.window.root: %@", self.window.rootViewController);
// gives <MMDrawerController: 0xdf578e0>
在某些时候,用户跳过或成功登录,在这种情况下,我从 WelcomeViewController 触发此代码:
// WelcomeViewController.m
- (void)userSuccessfullySignedIn
{
[self.presentingViewController dismissViewControllerAnimated:true completion:self.successBlock];
// NSLog(@"self.presentingViewController: %@", self.presentingViewController);
// gives <MMDrawerController: 0xdf578e0>
}
我认为我在 presentingViewController
而不是 self
上调用 dismiss 是正确的,但是 dealloc 永远不会被调用:
- (void)dealloc
{
NSLog(@"dealloc was called");
}
因此,我的 WelcomeViewController 实例仍保留在内存中,即使我已将其关闭。正如您从我的控制台输出中看到的那样,呈现和关闭发生在同一个 MMDrawerController 实例中。
我需要做什么才能正确关闭它并释放它的内存?
最佳答案
经过令人恼火的一天,事实证明这是 Taplytics v1.2.24 中的一个错误。该错误已在 1.2.32 中修复。
他们在 UIBarButtonItem 上有一个类别,他们在其中进行一些方法调配,并且持有对 rightBarButtonItem(我的 viewController)目标的强引用。这反过来又阻止了我的 UIViewController 解除分配。
关于ios - 呈现的 UIViewController 没有在解雇时被释放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22184376/