iphone - UI update in selector -


i perform selector in application:

- (void) dofilter:(uibutton*)button {     [activityindicator startanimating];     [self disablebuttons];     // ...     // actions         // ...     sleep(2);     [self enablebuttons];     [activityindicator stopanimating];     } 

when user clicks on button. activityindicator uiativityindicatorview. don't see activity indicators while code performing. how can fix it?

firstly, should never ever use sleep on main thread. blocks entire app , user can't time.

secondly, ui not updated until code returns control run loop. whenever call startanimating , stopanimating in same method without returning run loop in between, can sure nothing happen in ui (same disablebuttons , enablebuttons).

solution: call startanimating , disablebuttons. start tasks have perform in background ui not blocked. can use nsoperation, performselectorinbackground:..., grand central dispatch etc. that. finally, when long task finished, have call method on main thread calls stopanimating , enablebuttons.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -