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

Python __call__ special method practical example -

How can I edit my VIM config so that Vim treats ".ejs" files the same as it currently treats my html files? -