我不明白我在哪里打蛋。我需要更新progreesView的进度。我在IB中创建UIProgressView并仅更改颜色。我有财产和下一个代码
@property (weak, nonatomic) IBOutlet UIProgressView *progressView;
属性连接到IB的插座
- (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...
}
睡眠效果很好,但UIProgressView的进度不随时间变化。我错的地方?
答案 0 :(得分:4)
sleep()阻塞主线程,因此不会发生UI更新。您需要使用NSTimer或类似的东西。