Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 是否使用计时器填充自定义UITableViewCell?_Ios_Uitableview - Fatal编程技术网

Ios 是否使用计时器填充自定义UITableViewCell?

Ios 是否使用计时器填充自定义UITableViewCell?,ios,uitableview,Ios,Uitableview,我在UITableViewCell unsigned long long seconds = milliseconds/1000; unsigned long long minutes = seconds/60; unsigned long long hours = minutes/60; seconds -= minutes * 60; minutes -= hours * 60; NSString * result1 = [NSString `enter code here`string

我在
UITableViewCell

unsigned long long seconds = milliseconds/1000;
unsigned long long minutes = seconds/60;
unsigned long long hours = minutes/60;

seconds -= minutes * 60;
minutes -= hours * 60;

NSString * result1 = [NSString `enter code here`stringWithFormat:@"%02lluH:%02lluM:%02lluS",hours,minutes,seconds];

self.menushowTime.text = result1;//populate cell label with time

每当我重新加载表视图时,我的计时器都以2倍的速度运行,我的意思是非常快。如何防止这种情况发生。

先计算分钟,再计算秒 将代码更改为下面的

minutes -= hours * 60;
seconds -= minutes * 60;
是的,会发生这种情况,因为计时器已连接到
nsrunlop
,因此当
UI线程
忙于制作动画时,
nsrunlop
必须停止。它完成动画,然后增加计时器。因此,计时器在这段时间内不会完全增加

在1以下使用

[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];

你是如何计算毫秒的?hm=components.hour*3600000;NSU整数mm=组件。分钟*60000;NSUSM整数=components.second*1000;currentTime=hm+mm+sm;NSLog(@“显示当前时间%lld”,currentTime);这就是我计算的方式,一切正常,当我开始滚动tableview或重新加载tableview时面临问题我完全不知道如何启动计时器,因为我是一个新手,你能提供一些关于如何在UITableViewCell中显示时间的好例子吗,现在将其添加到runLoop中,如图所示。问题仍然存在吗?不,我通过每秒启动计时器解决了这个问题。最初,我每毫秒启动一次计时器。非常感谢。我还包括了commonmode和runLoop以及计时器。
[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];