我不明白我在哪里产卵。我需要更新 progreesView 的进度。我在 IB 中创建 UIProgressView 并仅更改颜色。我有属性(property)和下一个代码
@property (weak, nonatomic) IBOutlet UIProgressView *progressView;
属性连接到 IB 中的 socket
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"DefaultSS.png"]];
}
- (void) viewDidAppear:(BOOL)animated
{
[self connectToServer];
}
- (void) connectToServer
{
//some code...
sleep(2);
[self.progressView setProgress:0.2 animated:YES];
sleep(1);
[self.progressView setProgress:0.4 animated:YES];
sleep(1);
[self.progressView setProgress:0.7 animated:YES];
sleep(1);
[self.progressView setProgress:1.0 animated:YES];
sleep(1);
//some code...
}
Sleep 效果很好,但 UIProgressView 的进度不随时间变化。我哪里搞错了?
最佳答案
sleep() 会阻塞主线程,因此不会发生 UI 更新。您需要使用 NSTimer 或类似的东西。
关于ios - UIProgressView不显示进度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15256424/