美文网首页
防止NSTimer内存循环应用的解决办法之一。

防止NSTimer内存循环应用的解决办法之一。

作者: 王正魁 | 来源:发表于2021-05-31 14:23 被阅读0次

@interface WZKTimerTestVC ()

@property (strong ,nonatomic) NSTimer *timer;

@end

@implementation WZKTimerTestVC

- (void)viewDidDisappear:(BOOL)animated{

    [superviewDidDisappear:animated];

    [self.timer invalidate];

    self.timer=nil;

}

///创建Timer定时器

- (void)creatTimer {

    [[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];

}

///倒计时执行函数

- (void)timerForOverTimeOrder {

}

///getting

- (NSTimer*)timer{

    if(_timer==nil) {

        WeakSelf;

        _timer = [NSTimer timerWithTimeInterval:1 target:weakSelf selector:@selector(timerForOverTimeOrder) userInfo:nil repeats:YES];

    }

    return_timer;

}

@end

相关文章

网友评论

      本文标题:防止NSTimer内存循环应用的解决办法之一。

      本文链接:https://www.haomeiwen.com/subject/uzcxsltx.html