ios - loop doesnt change label as i want it to in objective c -


this question has answer here:

i playing around objective c on xcode, may seem dumb question here block of code, works doesnt work how want to.

        int = 10;     int x = 0;     {          printf("count is: %i\n", x);         nsstring *result = [[nsstring alloc] initwithformat: @"%i", x];         counting.text = result;         x++;         usleep(1000000);     } while (x < i); 

it changes label 9 @ end of loop, prints console fine, supposed count 0 9 , show on app. think need todo multi threading examples in java, cant apply them language

as people mentioned in comments, problem because usleep(1000000) freezing main thread, responsible interations ui, including updating it.

if change sleep line [[nsrunloop currentrunloop] rununtildate:[nsdate datewithtimeintervalsincenow:1]];, code should work expect, without need of using threads:

int = 10; int x = 0; {      printf("count is: %i\n", x);     nsstring *result = [[nsstring alloc] initwithformat: @"%i", x];     counting.text = result;     x++;     [[nsrunloop currentrunloop] rununtildate:[nsdate datewithtimeintervalsincenow:1]]; } while (x < i); 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -