Ios 当用户点击后退按钮(UINavigationController)时停止计时器运行

Ios 当用户点击后退按钮(UINavigationController)时停止计时器运行,ios,Ios,我正在使用UINavigationController。当用户点击后退按钮时,如何停止(调用invalidate方法)计时器。//将此viewDidLoad放入并确保有一个模仿后退按钮的back.png UIImage *buttonImage = [UIImage imageNamed:@"back.png"]; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setImage:buttonIma

我正在使用UINavigationController。当用户点击后退按钮时,如何停止(调用invalidate方法)计时器。

//将此viewDidLoad放入并确保有一个模仿后退按钮的back.png

UIImage *buttonImage = [UIImage imageNamed:@"back.png"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:buttonImage forState:UIControlStateNormal];
button.frame = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height);
[button addTarget:self action:@selector(backPressed:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:button];
self.navigationItem.leftBarButtonItem = customBarItem; 

- (void)backPressed:(id)sender {
     [yourTimer invalidate];
  }
如果计时器正在另一个类中运行,请使用NSNotificationCenter在backPressed方法中发布通知


请参见此处的NSNotification Center示例

我想您可以使用
查看将消失
方法间接检测何时按下back并使计时器无效

您尝试了什么?ViewWillEnglish呢?很好的一点王牌传奇,我不确定如何解决这个问题,我花了一些时间研究堆栈溢出和文档,但作为一名新的iOS开发人员,我没有走多远。下一次我一定要概述一下我试过的。谢谢,这很有效。我假设这种方法(创建自定义后退按钮)意味着我无法利用UINavigationController自动生成的后退按钮?这也很有效,似乎是创建自定义按钮的更简单解决方案。事实上。我真希望我能早点发表我的评论。:)