2

I don't understand where I lay an egg. I need to update progress of progreesView. I create UIProgressView in IB and change only color. I have property and next code

@property (weak, nonatomic) IBOutlet UIProgressView *progressView;

property connect to outlet in 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...
 }

Sleep work well, but progress of UIProgressView don't change with time. Where I mistaked?

rooftop
  • 3,031
  • 1
  • 22
  • 33
Neznajka
  • 305
  • 5
  • 19

1 Answers1

4

sleep() blocks the main thread, so no UI updates will happen. You need to use NSTimer or something similar.

jsd
  • 7,673
  • 5
  • 27
  • 47
  • ...or he can use the `[NSThread sleepForTimeInterval:1.f];` which works on the main thread as well. – holex Mar 06 '13 at 21:43