tags:

views:

29

answers:

1

Hi There,

My application has a button when clicked it is disabled, an activity indicator displayed and a background task is executed. When this task is completed a callback updates the interface by enabling the button and removing the activity indicator. The problem I having is the task is completing the callback function is executed but for a period of time the activity monitor remains on the screen, the button looks like it is disabled but it is possible to click it again. Can anyone tell me where I am going wrong?

Thanks very much!

+1  A: 

could it be that the callback-method is being executed in a separate thread? I'm asking, because any calls that have impact on a view should be performed on the main thread.

the problem might be solved by doing the following: 1) create a Method that handles your UI-related code and gets called within your callback method 2) the UI-related code has to be performed on the main thread

it could look a little bit like this:

//gets called asynchronously when your operation has completed
-(void)myCallbackHandler {
[self performSelectorOnMainThread:@selector(updateUI) withObject:nil 
                                                      waitUntilDone:NO];
}

-(void)updateUI {
[myActivityIndicatorView stopAnimating];
[myButton setEnabled:YES];
}

cheers sam

//edit for format, still looks crap, only opera here...

samsam
Hey Sam, This dawned on me about a few minutes ago. Thanks very much for the answer confirmed what I was thinking. Cheers Sj
Sjblack
you're welcome!
samsam