【发布时间】:2012-05-02 09:27:36
【问题描述】:
我正在尝试在“while 循环”中更新 UILabel,但它不会更改 UILabel 文本。我知道它像往常一样在主线程的当前运行循环周期结束时显示为iOS。但是如何解决这个问题(ftp.AsyncFinished函数是由外部chilkat ftp模块提供的):
数据每秒更新一次。我搜索了这个论坛和 Apple 的文档,但我找不到在主线程的“while 循环”中更新 UILabel 的正确方法。我可以用什么来代替while循环,它允许主线程更新UILabel。
while (ftp.AsyncFinished != YES) {
// here is the code getting data from the cilkat FTP module stored in PercentOfFile and MinutesRemaining
NSString *content =[[NSString alloc] initWithFormat:@"%.0f%% done%.0fmin left",PercentOfFile,MinutesRemaining ];
[LabelProgress setText:content];
}
【问题讨论】:
-
@Habbib.OSU 请注意,
runMode:beforeDate:方法非常危险。我已经基于 GCD 为该问题添加了更好的解决方案。
标签: objective-c ios while-loop uilabel