NSTimer

懵懂的女人 提交于 2019-12-02 11:23:55

1. block

示例代码:

@property (nonatomic, strong) NSTimer *timer;

// 1. 初始化定时器
self.timer = [NSTimer timerWithTimeInterval:1 repeats:YES block:^(NSTimer * _Nonnull timer) {
}];

// 2. 将定时器加入RunLoop
[[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSDefaultRunLoopMode];

// 3. 将定时器移出RunLoop
[self.timer invalidate];

引用关系图:

引用
引用
UIViewController
NSTimer
NSRunLoop
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!