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
Post a Comment