NStimer 在滚动ScrollView的时候停止,在新线程中使用NSTimer
2012-02-19 18:11
330 查看
方法一:
-(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) 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 在滚动ScrollView的时候停止,在新线程中使用NSTimer
- 关于EditText与ScrollView嵌套使用时候出现的Edittext自动滚动至最顶部的问题
- EF Core使用SQL调用返回其他类型的查询 ASP.NET Core 2.0 使用NLog实现日志记录 CSS 3D transforms cSharp:use Activator.CreateInstance with an Interface? SqlHelper DBHelper C# Thread.Abort方法真的让线程停止了吗? 注意!你的Thread.Abort方法真
- Android下 scrollview的滚动停止事件的监听方法
- 多线程——停止线程(intertupt方法setDaemon和方法的使用)
- 使用StoryBoard设置Scrollview的横向滚动不用一行代码
- 屏幕滚动控件ScrollView的使用
- 在新线程中使用NSTimer
- iOS的ScrollView包含TableView使用AutoLayout实现滚动
- uiscrollview滚动时候nstimer会失灵
- c#中跨线程调用windows窗体控件 .我们在做winform应用的时候,大部分情况下都会碰到使用多线程控制界面上控件信息的问题。然而我们并不能用传统方法来做这个问题,下面我将详细的介绍。
- MFC 线程创建在使用构造函数进行初始化线程的时候,创建线程实例了,但是线程并没有执行的问题
- 31-使用scrollView以及pageControl,NSTimer实现图片轮播
- [并发并行]_[任务停止]_[使用Pthread的线程本地存储来停止任务执行]
- 使用线程实现视图平滑滚动
- android 关于判断scrollView滚动停止
- Android中滚动视图(ScrollView、HorizontalScrollView)的使用
- Android 监听ScrollView时候滚动到了底部
- ScrollView 滚动到指定位置(需要用到线程更新)
- 哪些年遇到过的Andriod问题(8)Handler使用 mars.barhandler中的错误(测试) 线程中停止线程?