ios - How to change instantly a button to an activity indicator in xcode 6 -


i'm trying change button in navigation bar activity indicator instantly when pressed. tryed code, button change when ibaction process end:

- (bool)connected { reachability *reachability = [reachability reachabilityforinternetconnection]; networkstatus networkstatus = [reachability currentreachabilitystatus]; return networkstatus != notreachable; }  - (ibaction)scaricadatabase:(id)sender { if (![self connected]) {     _navtitle.leftbarbuttonitem = [[uibarbuttonitem alloc] initwithtitle:@"non connesso" style:uibarbuttonitemstyleplain target:nil action:nil]; } else {     uiactivityindicatorview *activityindicator = [[uiactivityindicatorview alloc] initwithframe:cgrectmake(0, 0, 20, 20)];     uibarbuttonitem * barbutton = [[uibarbuttonitem alloc] initwithcustomview:activityindicator];     activityindicator.color = [uicolor blackcolor];      // set left or right     [activityindicator startanimating];     [[self navtitle] setleftbarbuttonitem:barbutton];      nsstring *dropboxhttpsurl = @"https://dl.dropboxusercontent.com/u/68843065/eventimedievale.sql";     nsdata *dbfile = [[nsdata alloc] initwithcontentsofurl:[nsurl urlwithstring:dropboxhttpsurl]];      if(dbfile) {         nslog(@"%lu", (unsigned long)[dbfile length]);         nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes);         nsstring *documentsdirectory = [paths objectatindex:0];         nsstring *appfile = [documentsdirectory stringbyappendingpathcomponent:@"eventimedievaleupd.sql"];         [dbfile writetofile:appfile atomically:yes];         nslog(@"%@", appfile);         _navtitle.leftbarbuttonitem = [[uibarbuttonitem alloc] initwithtitle:@"aggiornato" style:uibarbuttonitemstyleplain target:nil action:nil];     }else{         nslog(@"file non scaricato");     } } 

i need show activity indicator when process downloading sql file, update of navigation bar @ end of process.

could me?

thanks :)

i try placing nsdata download portion background thread using grand central dispatch. should go within ibaction

uiactivityindicatorview *activityindicator = [[uiactivityindicatorview alloc] initwithframe:cgrectmake(0, 0, 20, 20)]; uibarbuttonitem * barbutton = [[uibarbuttonitem alloc] initwithcustomview:activityindicator]; activityindicator.color = [uicolor blackcolor];  // set left or right [activityindicator startanimating]; [[self navtitle] setleftbarbuttonitem:barbutton]; dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_high, 0), ^{ // 1         //load data here         dispatch_async(dispatch_get_main_queue(), ^(void) {             //remove activity indicator          });     }); 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -