Reputation: 371
Could somebody help me a little bit with my issue below?
When I call the myFunction, images which I want to set to buttons appear after 2 sec simultaneously, not one by one with delay of 0.5 sec.
More info:
-(IBAction) myFunction:(id) sender {
int i, value;
for (i = 0; i<[generatedNumbers count]; i++) {
value = [[generatedNumbers objectAtIndex:i] intValue];
UIButton *button = (UIButton *)[self.view viewWithTag:i+1];
UIImage *img = [UIImage imageNamed:[NSString stringWithFormat:@"%d.png",value]];
[button setImage:img forState:UIControlStateNormal];
[img release];
usleep(500000);
}
}
Upvotes: 0
Views: 1278
Reputation: 19071
What's probably happening is that this method is running on the main thread. Since it waits to finish when you call usleep()
, the run loop never gets to the point where it's going to update the UI. Try creating an NSTimer
and firing off a separate method every .5 seconds; that should give the main thread enough time to update.
Upvotes: 3