UILabel display regular updates whilst loop is being executed -
i have long loop calculation. in order give user idea of progress prefer update of output data displayed in uilabels user can view interim output.
// run activity year (int day = 1; day < 366; day++) { (int hour = 1; hour < 25; hour++) { (int minute = 1; minute < 61; minute++) { display = (day*10000)+(hour*100)+minute; self.displaytest.text = [[nsstring alloc] initwithformat: @"%d", display]; } } }
obviously self.display.text won't updated until -(void) viewdidappear:(bool)animated
has completed.
how refresh data, whenever hour loop completed? put in phantom button , refresh it. strikes me little crude. don't want have resort using activity indicator or progress view. thanks.
why not perform logic on separate nsthread
, run ui updates on main thread occasionally? example, each time "hour" iterations finished (reached 24, after each "day"), perform ui logic on main thread.
example:
- (void)updateui:(nsnumber*)display { self.displaytest.text = [[nsstring alloc] initwithformat: @"%@", display]; } - (void)yearstuff { (int day = 1; day < 366; day++) { int display; (int hour = 1; hour < 25; hour++) { (int minute = 1; minute < 61; minute++) { display = (day*10000)+(hour*100)+minute; } } [self performselectoronmainthread:@selector(updateui:) withobject:[nsnumber numberwithinteger:display] waituntildone:yes]; } } - (void)viewdidappear:(bool)animated { [self performselectorinbackground:@selector(yearstuff) withobject:nil]; }
Comments
Post a Comment