tags:

views:

1144

answers:

1

Hi

I want a button in my navbar which lets the user refresh the contents of a tableview. The tableview is already populated and once the user presses the refresh button, I want to show a UIActivityIndicator while I fetch the items to be displayed on the table.

I tried putting a [indicator startAnimating] before calling the method to get the new data of the table (where indicator is of type IBOutlet UIActivityIndicator* and mapped to a control in IB) but the indicator does not show up. Instead, the navbar refresh button is in the pressed position till control returns from this IBAction method.

How can I show the indicator while the method execution completes?

Thanks.

+2  A: 

You need to get the new data for the table in the background. That could be an asynchronous network call or a thread depending on what your refresh code does but the UI kind of assumes that button presses are pretty much instantaneous.

You'll note that your whole UI locks up (not just the refresh button), so this is a good thing to do anyway albeit much harder to implement.

Stephen Darlington
Thanks Stephen. But now even on doing this [self.view setUserInteractionEnabled:NO], user can press any buttons. I am writing this statement just before detaching a new thread and am enabling user interaction only after processing is complete. But I can still press buttons while processing is on.
lostInTransit