ios - UINavigationController 在 popViewControllerAnimated 之后不释放/销毁 Controller ?

标签 ios uinavigationcontroller popviewcontrolleranimated

在过去的几天里,我试图调查我最近发现的非常奇怪的情况。 问题是推送的 Controller 在 popViewControllerAnimated: 调用后看起来还活着。 我创建了一个简单的测试项目(ARC enabled),在根导航 Controller 中嵌入了两个 Controller ,并且该行为已被重现。 enter image description here 这是触发第二个 Controller 的第一个 viewController 代码:

-(IBAction)push:(id)sender {
    [self performSegueWithIdentifier:@"vseg" sender:nil];
}

从我的角度来看没有什么不寻常的。第二个 Controller 中有一个方法,每秒由计时器调用:

-(void) ticker {
    NSLog(@"from ViewController2 %d", tickerCount++);
    _counterLabel.text = [NSString stringWithFormat:@"tick: %d", tickerCount];
    [self performSelector:@selector(ticker) withObject:nil afterDelay:1];
}

仍然没有异常 - 应用程序按预期运行,UILabel 更新并增加了 tickerCount 值,消息出现在控制台上。 接下来我们点击返回按钮,弹出第一个 Controller ,控制台继续接收来自第二个 Controller 的消息。 enter image description here

我还是不知道它到底是什么意思?整个 Controller 是否保持未发布状态,或者只是由一些对我没有意义的 clousure 变量持有的自动收报机方法。 这是测试项目 http://hxml.ru/EliEX

最佳答案

取消选择器只需使用

[NSObject cancelPreviousPerformRequestsWithTarget:self];

[NSObject cancelPreviousPerformRequestsWithTarget:selector:object:]

目标是调用 performSelector:afterDelay: 的原始对象

- (void)viewWillDisappear:(BOOL)animated
{
   [NSObject cancelPreviousPerformRequestsWithTarget:self];
}

引用Run LoopsNSObject文档

关于ios - UINavigationController 在 popViewControllerAnimated 之后不释放/销毁 Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20608068/

相关文章:

ios - popViewControllerAnimated 后 UITextField 内容为空

ios - 从 ios 应用程序的 SWIFT 中的自定义单元格按钮转到另一个 View

iOS:viewWillDisappear 没有在从另一个 View Controller 动画的 popViewController 上被调用

IOS : Custom Layouts does not work, CollectionView:cellForItemAtIndexPath: 未调用方法

ios - 使用 uinavigationcontroller 时的全屏背景图像

swift - 快速更改UITabBar中 “More” UINavigationController的背景颜色

ios - 将数据传输回根 ViewController

ios - 为什么我的 tableview 直到第二次触摸才调用 didselectrowatindexpath?

ios - 替换 CGBitmapContext 中的特定颜色

ios - NSPredicate predicateWithFormat : still counting previously deleted data