ios - UIAlertview hanging while the thread in background is loading data -
i have uibarbuttonitem called "refresh data". when user clicks it, app should refresh data. happens on button click web services launched , xml info brought , of order 30000-40000 records. prevent ui hanging wrote background thread , did loading there.
- (void)refreshdataaction { nslog(@"refresh data"); //put alert box indicating user wait while info loading. uialertview *alert = [[uialertview alloc] initwithtitle:@"data loading" message:@"please wait while info beingness refreshed." delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil, nil]; alert.tag = 10; [alert show]; } - (void)alertview:(uialertview *)alertview clickedbuttonatindex:(nsinteger)buttonindex { nslog(@"hit in clickedbuttonatindex alertview @ 259"); self.refreshactindicator.hidden = no; [self.refreshactindicator startanimating]; dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_default, (unsigned long)null), ^(void) { [self getallcustomervalues]; nserror *nwerror = nil; if (![self.secondmoc save:&nwerror]) { nslog(@"209 failed save sec moc"); } else { //nslog(@"saved success"); } }); } like can see alert view shows up. click ok , box still there "blackened" , hanging there on screen. , 7-8 seconds later box disappears , animation starts activity indicator. goal this. 1.user clicks on refresh info button. 2.alert view shows up. 3.user clicks ok. 4.alert box disappears , background thread starts working , see activity indicator working/animating.
user know wait while activity indicator animating. how app start animating after user clicks "ok" , alertview ok not blackened. clear?if need more information, please ask. thanks
edit: screen has background thread working on when loads first time day. there screen before this. on have go on button , clicking launches background thread same thing 1 on here.i dont kill or anything.
edit 2:
- (void)refreshdataaction { nslog(@"refresh data"); self.txtcustomersearch.text =@""; [self cleanuppreviouslabels]; //put alert box indicating user wait while info loading. uialertview *alert = [[uialertview alloc] initwithtitle:@"data loading" message:@"please wait while info beingness refreshed." delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil, nil]; //alert.tag = 10; //[alert show]; [alert performselectoronmainthread:@selector(show) withobject:nil waituntildone:false]; nslog(@"hit in willpresenet alertview @ 221"); self.refreshactindicator.hidden = no; [self.refreshactindicator startanimating]; nslog(@"dispatching"); //disable view , other controls self.txtcustomersearch.userinteractionenabled =no; self.txtcustomersearch.enabled =no; self.btnsearch.enabled =no; self.btnsearch.userinteractionenabled = no; self.scrollview.userinteractionenabled = no; //self.view.userinteractionenabled =no; self.chkbutton.enabled = no; [self deletepreviousvalues]; dispatch_async(dispatch_get_global_queue( dispatch_queue_priority_low, 0), ^{ nslog(@"getting client values"); [self getallcustomervalues]; nslog(@"got client values"); nserror *nwerror = nil; if (![self.secondmoc save:&nwerror]) { nslog(@"209 failed save sec moc"); } else { //nslog(@"saved success"); } self.txtcustomersearch.userinteractionenabled = yes; self.txtcustomersearch.enabled =yes; self.btnsearch.enabled =yes; self.btnsearch.userinteractionenabled = yes; self.scrollview.userinteractionenabled = yes; self.view.userinteractionenabled =yes; self.chkbutton.enabled = yes; [self.refreshactindicator stopanimating]; nslog(@"saved"); }); nslog(@"dispatched"); }
try changing
dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_default, (unsigned long)null), ^(void) { to background priority
dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_background, (unsigned long)null), ^(void) { ios animation uialertview uiactivityindicatorview immediate
No comments:
Post a Comment