刷新iPhone进度条

时间:2010-09-20 19:11:02

标签: iphone objective-c cocoa-touch progress-bar

我如何显示进度条正在工作,目标-c中没有Refresh(),就像在.net中我会使用什么

例如

contactprogress.progress = 0.5;   
StatusLabel.text = @"Status: Address Found";

如何刷新视图以显示进度已发生变化&向用户显示StatusLabel状态?

谢谢

梅森

3 个答案:

答案 0 :(得分:1)

根据您对其他两个响应的评论,您正在执行一些计算密集型任务,需要几秒钟,并且视图在任务期间不会更新。您可以尝试使用两个线程(不像听起来那么可怕),以便UI可以在任务执行时继续更新。

Here is an example.

iOS Reference Library Threading Programming Guide

答案 1 :(得分:0)

要重绘UIView,您可以使用

[UIView setNeedsDisplay];

但是,只有在极少数情况下才需要这样做。当你改变时,让我们说一个标签的内容,你的UI应该立即更新。您可能希望为您的问题提供更多代码/上下文。

答案 2 :(得分:0)

听起来你想要在一段时间间隔内重复更新进度条和一些文本。你可以使用一个简单的计时器。了解计时器here。也许是这样的:

[NSTimer scheduledTimerWithTimeInterval:0.1f target:self selector:@selector(refreshProgress) userInfo:nil repeats:YES];

- (void) refreshProgress:(id)sender {
  // figure out new progress bar and text values
  contactprogress.progress = 0.5;   
  StatusLabel.text = @"Status: Address Found";

  // check if we should stop the timer and hide the progress bar/status text
}

这将每0.1秒使用新值更新您的进度条。

相关问题