objective c - How to update UI, wait some time and update it again using threads in iOS? -


i have app need blue button text 'hello' glow red , show word 'alert'. revert blue , text 'hello'. how can it?

i know how use threads model-based tasks, not ui-based tasks, apparently have on main thread. not in using blocks though.

basically thing want (in pseudo-code):

- (void) animateuiandrevertaftersometime {    // update button title @"alert" using settitle: forstate:   [self.thisbutton settitle: @"alert" forstate:uicontrolstatenormal;   // set buttons' backgroundcolor redcolor   self.thisbutton.backgroundcolor = [uicolor redcolor];    // start timer 10 seconds   // once time   {       // update button title @"hello" using settitle: forstate:       [self.thisbutton settitle: @"hello" forstate:uicontrolstatenormal;       // set button's backgroundcolor bluecolor        self.thisbutton.backgroundcolor = [uicolor bluecolor];   } } 

can above in objective-c without hanging app interface 10 seconds? :p

performselector:withobject:afterdelay: can this:

- (void) animateuiandrevertaftersometime {   // update button title @"alert" using settitle: forstate:   [self.thisbutton settitle: @"alert" forstate:uicontrolstatenormal;   // set buttons' backgroundcolor redcolor   self.thisbutton.backgroundcolor = [uicolor redcolor];   // start timer 10 seconds   // once time   [self performselector:@selector(updatebutton) withobject:nil afterdelay:10]; }   -(void)updatebutton   {   // update button title @"hello" using settitle: forstate:   [self.thisbutton settitle: @"hello" forstate:uicontrolstatenormal];   // set button's backgroundcolor bluecolor    self.thisbutton.backgroundcolor = [uicolor bluecolor]; } 

alternatively can use nstimer achieve same thing:

[nstimer scheduledtimerwithtimeinterval:10                                  target:self                                selector:@selector(updatebutton)                                userinfo:nil                                 repeats:no]; 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

c# - Unity IoC Lifetime per HttpRequest for UserStore -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -