runLoop运行模式示例代码
来源:互联网 发布:ios数据恢复工具 编辑:程序博客网 时间:2024/04/30 04:06
runLoop运行模式示例代码
通过 timer2 这种方式创建定时器,不再需要手动添加到runloop里面,该方法内部会自动添加,并且设置运行模式为默认模式。
要注意的是 子线程的runloop是需要自己创建的
#import "ViewController.h"@interface ViewController ()@end@implementation ViewController-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{// [self timer2]; [NSThread detachNewThreadSelector:@selector(timer2) toTarget:self withObject:nil];}-(void)timer{ //创建定时器 NSTimer *timer= [NSTimer timerWithTimeInterval:2.0 target:self selector:@selector(run) userInfo:nil repeats:NO]; //添加定时器到RunLoop中 //参数1:定时器 参数2: runloop的运行模式 [[NSRunLoop currentRunLoop]addTimer:timer forMode:NSDefaultRunLoopMode];}-(void)timer2{ NSRunLoop *runloop=[NSRunLoop currentRunLoop]; [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(run) userInfo:nil repeats:NO]; [runloop run];}-(void)run{ NSLog(@"------%@-------%@",[NSThread currentThread],[NSRunLoop currentRunLoop].currentMode);}@end
0 0
- runLoop运行模式示例代码
- 工厂模式示例代码
- 原型模式示例代码
- 原型模式代码示例
- 合成模式代码示例
- 命令模式代码示例
- 适配器模式代码示例
- 观察者模式示例代码
- 代理模式代码示例
- RunLoop iOS运行回路
- 91- 运行循环:RunLoop
- RunLoop运行循环
- runloop 的运行原理
- 十一.运行环-runloop
- 运行循环-RunLoop
- 纯代码解释runloop
- Builder 设计模式 代码示例
- 装饰者模式示例代码
- PAT A1096 consecutive factors
- android控件使用-----SpannableString
- python爬虫原理解析
- Bean的作用域
- 理解事务的4种隔离级别
- runLoop运行模式示例代码
- Android中线程池的总结
- Android开发 读取assets下的TXT文本一直提示找不到文件
- 牛人写的设计游戏服务器
- 自定义AlertDialog弹窗
- Android Service与AIDL的使用
- [DP] BZOJ 1974 [Sdoi2010]auction 代码拍卖会 & 51Nod 1261 上升数
- c++primer第二章
- 数据库MySql的增删改查