NSTimer与UITableView同时使用

来源:互联网 发布:淘宝店铺突然不存在了 编辑:程序博客网 时间:2024/06/06 00:04

 

如果使用默认的设置,在滑动tableview时,timer不会触发时间函数,因为他们使用共同的runloop而tableview的滑动阻止了timer的函数调用。要实现并行,可以如下:

NSTimer* timer = [NSTimertimerWithTimeInterval:0.005target:selfselector:@selector(timerFireMethod:)userInfo:@"finishAnimation"repeats:YES];

    NSRunLoop *currentRunLoop = [NSRunLoopcurrentRunLoop];

    [currentRunLoop addTimer:timer forMode:NSRunLoopCommonModes];

主要是设置mode即刻。
 
 
tableview 滑动导致delegate 回调停止 解决办法

// request回调

NSURLRequest *request = ...

NSURLConnection *connection = [[NSURLConnection alloc]
                                               initWithRequest:request
delegate:self
                                             startImmediately:NO];
[connection scheduleInRunLoop:[NSRunLoop currentRunLoop]
                                            forMode:NSRunLoopCommonModes];
[connection start];

原创粉丝点击