2011-02-11 89 views
0

在我的应用程序中,我有一个UILabel显示每秒钟更新的时间。 我也有可拖动的对象在屏幕上。 当我隐藏标签或停止计时器时,一切都很完美,但是当我启动计时器时,拖动对象的动画性能下降。 我把UILabel更新在一个单独的线程,但没有运气。 我需要帮助的朋友:)Ios UILabel更新性能

+1

请发表您的代码中,你所创建的计时器,它的选择 – iHS 2011-02-11 10:54:12

回答

0

这是我的代码:

self.timer =的NSTimer scheduledTimerWithTimeInterval:1个目标:自我选择:@选择(的OnTimer :)用户信息:无重复:YES]; (无效)onTimer:(NSTimer *)timer; {

timeInterval ++; 
int hours = (int)timeInterval/3600; 

int minutes = (timeInterval %3600)/ 60; 
int seconds = ((timeInterval%3600)%60); 
NSString *timeDiff = [NSString stringWithFormat:@"%d:%02d:%02d", hours,minutes,seconds]; 

[NSThread detachNewThreadSelector:@selector(setText:) toTarget:self.time withObject:timeDiff]; 

}

+0

标签每秒更新一次,导致UI拖动性能下降?也许你还应该发布你的拖动代码。此外,您无法在主线程之外更新GUI。如果你这样做,它可能似乎“工作”......直到它没有,并且你的应用程序以随机​​和不可重复的方式失败。 – Bogatyr 2011-02-11 12:00:13