当前位置:网站首页>OC-NSTimer
OC-NSTimer
2022-08-09 11:08:00 【彭同学她同桌】
必须运行在NSRunLoop上
@interface A:NSObject
-(void)openTimer;
-(void)doAction:(NSTimer*)timer;
@end
@implementation A
-(void)openTimer
{
NSDictionary *info = @{
@"name":@"dahuang"};
//创建计时器,自动将计时器放入runloop
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(doAction:) userInfo:nil repeats:YES];
//TimeInterVal是时间也就是每多少秒执行一次 target是执行的函数在哪 selector是要执行的方法是什么 userInfo执行函数之后会打印相应信息 repeats是是否重复执行
//手动开启runloop
[[NSRunLoop mainRunLoop]run];//手动开启runloop
//创建计时器 但是不会自动放进计时器
NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(doAction:) userInfo:nil repeats:YES];
//手动将计时器放进runloop
[NSRunLoop mainRunLoop]addTimer:timer forMode:NSDefaultRunLoopMode];
[[NSEunLoop mainRunLoop]run];
}
-(void)doAction:(NSTimer*)timer
{
NSLog(@"%s",__func__);
}
@end
int main()
{
A *a = [[A alloc]init];
[a openTimer];//
return 0;
}
fire
[timer fire]//会立即执行
invalidate
[timer invalidate]//立即停止
边栏推荐
- 华为VRRP+MSTP联动接口检测实验案例
- uni-app 自带的picker封装一个日期-时间选择器
- 最长回文子串
- pip常见命令和更改源文件
- golang 标准库json Marshal、Unmarshal坑
- vite的原理,手写vite
- Solve 1. tensorflow runs using CPU but not GPU 2. GPU version number in tensorflow environment 3. Correspondence between tensorflow and cuda and cudnn versions 4. Check cuda and cudnn versions
- PTA习题 阶梯电价(C)
- electron 应用开发优秀实践
- 自从我使用HiFlow场景连接器后,在也不用担心成为“落汤鸡”了
猜你喜欢

ThreadLocal及其内存泄露分析

Jmeter BeanShell post processor

Tensorflow realize parameter adjustment of linear equations

MDK添加注释模板

双向链表的各种操作

Antdv+Asp.net WebApi开发学生信息管理系统(一)

Multi-merchant mall system function disassembly 26 lectures - platform-side distribution settings

性能测试(03)-JDBC Request

支付宝小程序的接入

【VIBE: Video Inference for Human Body Pose and Shape Estimation】论文阅读
随机推荐
b站up主:空狐公子 --矩阵求导(分母布局)课程笔记
性能测试(01)-jmeter元件-线程组、调试取样器
Arduino学习总结 + 实习项目
CentOS6.5 32bit安装Oracle、ArcSde、Apache等配置说明
PTA 指定位置输出字符串(c)
Official explanation, detailed explanation and example of torch.cat() function
Numpy常用操作博客合集
golang源代码阅读,sync系列-Pool
性能测试(06)-逻辑控制器
美的数字化平台 iBUILDING 背后的技术选型
PTA 矩阵运算
gdb tui的使用
二叉树 前序是根在前(根左右)中序(左根右)
caffe ---make all编辑出错
1006 Sign In and Sign Out (25分)
无刷无霍尔BLCD电机控制
ACM最长不下降子序列问题
∘(空心的点乘)的数学含义
ACM01背包问题
torch.cat()函数的官方解释,详解以及例子