使 UIView 子中的 NSTimer 无效 class

Invalidate NSTimer inside UIView sub class

我正在寻找在 UIView 子类中使用 NSTimer 的解决方案。如果我尝试对另一个视图控制器进行 performsegue,它会将 运行 保留在后台。有人可以帮我解决这个问题吗?

NSTimer 必须在您的 UIView 子类中声明为 属性,以便它可以在您引用该视图的 UIViewController 中访问。

@property (nonatomic, strong) NSTimer *myTimer;

在执行 segue 时。

 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
       [self.myCustomView.myTimer invalidate];
}

尝试通过分配

使计时器对象为零
  [timerObject invalidate];
  timerObject  = nil;