2014-05-17 42 views
2

在一个课程中,我添加了一个UITableViewNSTimer。当我试图滚动UITableView冻结UITableView滚动因NSTimer而受到干扰

如果该NSTimer未被添加,那么UITableView工作得很好。

这是我添加NSTimer

if (self.timer != nil) 
{ 
    [self.timer invalidate]; 
    self.timer = nil; 
} 
self.timer = [NSTimer scheduledTimerWithTimeInterval:0.0 target:self 
             selector:@selector(updateClock) 
             userInfo:nil repeats:YES]; 
[[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes]; 

请给我建议任何解决方案,我是怎么得到错误代码。

+0

在其中添加此计时器的代码?它如何与你的tableview进行交互?请描述它的理解你的问题.. – Madhav

+0

我加入计时器** ** viewDidLoad **并在** xib **中添加UITableView。这个计时器显示一个数字时钟和tableView显示一些数据。 – Deepika

+1

因为0.0 timeInterval,所以你会尽可能经常地调用你的'updateClock'。如果您在主线程中执行某些操作,那么这就是为什么您的UI冻结的原因 – Argent

回答

1

应该叫定时器的至少0.1秒以上或1秒,随后如果你想使用更新时钟计时器您可以使用此代码应用程序的实现代码如下不会来袭

0

https://github.com/nacho4d/ClockView

如果你想要做执行,您可以使用其他操作:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){ 
    //Background Thread 
    dispatch_async(dispatch_get_main_queue(), ^(void){ 
     //Run UI Updates 
    }); 
});