objective c - Do two steps - one by one -


i can't figure out how this:

i have imageview , clicking the button i'd in imageview shown: first image, wait few seconds , while loop find second image (by following instructions in while loop many other images), , show chosen (second) image.

i'm not sure i've described issue clear here sample code:

- (ibaction)button:(id)sender {   i=0;   uiimage *img = [uiimage imagenamed:@"image1.png"];                  [first setimage:img];   /*some code sets time image1 stay shown*/   while (i<some_variable) {   /*blah blah blah*/   if (something) {uiimage *img = [uiimage imagenamed:@"image2.png"];                  [first setimage:img];}   if (something else) {uiimage *img = [uiimage imagenamed:@"image3.png"];                  [first setimage:img];}   ...   /*code code code*/   i++;   }  } 

this 1 hasn't solve problem:

[nsthread sleepfortimeinterval:1.0]; 

it wait's blank process code , show chosen image.

this should basic , can't think of idea.

this solved issue:

- (ibaction)button:(id)sender {    uiimage *img = [uiimage imagenamed:@"image1.png"];                  [first setimage:img];    double delayinseconds = 1.0; //set delay time     dispatch_time_t poptime = dispatch_time(dispatch_time_now, (int64_t)(delayinseconds * nsec_per_sec));     dispatch_after(poptime, dispatch_get_main_queue(), ^(void){   i=0;   while (i<some_variable) {   /*blah blah blah*/   if (something) {uiimage *img = [uiimage imagenamed:@"image2.png"];                  [first setimage:img];}   if (something else) {uiimage *img = [uiimage imagenamed:@"image3.png"];                  [first setimage:img];}   ...   /*code code code*/   i++;   }   }); } 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -