在新线程中使用NSTimer
来源:互联网 发布:辐射4原版捏脸数据 编辑:程序博客网 时间:2024/06/07 15:41
在新线程中使用NSTimer
方法一:
-(void) viewDidLoad{
[self performSelectorInBackground:@selector(call1) withObject:nil];
}
-(void) call1{
timer1 = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(doSomething) userInfo:nil repeats:NO];
[[NSRunLoop currentRunLoop] addTimer:timer1 forMode:NSRunLoopCommonModes];
}
-(void) call2{
// do something
timer1 invalidate];
timer1 = nil;
}
方法二:
- (void)viewDidAppear:(BOOL)animated { NSThread* timerThread = [[NSThread alloc] initWithTarget:self selector:@selector(timerStart) object:nil]; [timerThread start]; }-(void)timerStart{ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSRunLoop* runLoop = [NSRunLoop currentRunLoop]; timer = [[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(method) userInfo:nil repeats:YES] retain];//一定要retain,不然timerStart执行完后,NSTimer就被释放了。 [runLoop run]; [pool release];}- (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; [timer invalidate];}
方法三:
timer = [NSTimer timerWithTimeInterval:5.0 target:self selector:@selector(SendHeartBeat) userInfo:nil repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:heartTimer forMode:NSDefaultRunLoopMode];
- 在新线程中使用NSTimer
- 在新线程中使用NSTimer
- NStimer 在滚动ScrollView的时候停止,在新线程中使用NSTimer
- NStimer 在滚动ScrollView的时候停止,在新线程中使用NSTimer
- NSTimer和NSRunLoop在子线程中的使用
- NSTimer和NSRunLoop在子线程中的使用
- 在子线程中使用runloop,正确操作NSTimer计时的注意点 三种可选方法
- 在子线程中使用runloop,正确操作NSTimer计时的注意点 三种可选方法
- Android Handler/Looper/MessageQueue 在新线程中使用Handler
- NSTimer直接使用需要在主线程中使用
- NSTimer 在使用中需要注意的几个问题
- iOS中定时器NSTimer使用
- IOS中关于NSTimer使用
- IOS中关于NSTimer使用
- IOS 中NSTimer使用注意事项
- iOS中定时器NSTimer使用
- iOS中NSTimer的使用
- iOS中定时器NSTimer使用
- VS2008 添加service引用和web引用的区别
- DCOM的學習和配置
- Swing框架之Component
- table拼接大图片时,取消图片之间的空隙
- 使用java中汇编指令解析String对象(String s1="a";String s2=s1+"b";String s3=new String("a");String s4=s3+"a";)
- 在新线程中使用NSTimer
- js模式对话框
- Asp.Net日期时间格式设置
- AS3常用编程小方法——取数组最大值/最小值
- android中View坐标学习
- OPENFILENAME structure
- 用户 'IIS APPPOOL\IdealTest' 登录失败解决方案
- hdu1166 敌兵布阵
- rpm包制作实例