ios - Run background thread before UITableView Segues -


i have uitableview shows list of movies. (movie name , id stored in pre-populated array).

when click row, want app go background before segueing, download "movie info" , segue new view once background thread has finished. downloading of information works fine, have left out part of code.

however, can't seem logic right on how show spinner let user know going on , transition or fail upon background completion.

any help?

in uitableviewcontroller class

    - (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender {         moviedetailsviewcontroller *mvc = (moviedetailsviewcontroller*)segue.destinationviewcontroller;         mvc.movie = movie;     }      - (bool)shouldperformseguewithidentifier:(nsstring *)identifier sender:(id)sender  {     //i know if returns true prepareforsegue called      bool cansegue = no:         if ([identifier containsstring:@"seg_movie"]) {              // show activity spinner                [self domovielookup];                  if (movie != nil) {                     cansegue = yes;                 }          }         return cansegue;      }    - (void) domovielookup {     nsindexpath *indexpath = [self.tableview indexpathforselectedrow];      dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_default, 0), ^{         //here communcating server , parsing json results dictionary          //this code works fine send json results on object creation.         [self buildmoviewithdictionary:[[dictionaryresults objectforkey:@"movie"] objectatindex:0]];          dispatch_async(dispatch_get_main_queue(), ^{            //do need here?            //stop spinner          });      });  } 

just method creates movie object incase curios.

- (void) buildmoviewithdictionary : (nsdictionary*) dictionary {     movie = [[movie alloc] init];     movie.title  = [dictionary objectforkey:@"movietitle"];       movie.description  = [dictionary objectforkey:@"movietitle"];        movie.releasedate  = [dictionary objectforkey:@"movietitle"];        } 

you're close, bit out of order think. instead of calling domovielookup in shouldperformseguewithidentifier:sender:, try doing in tableview:didselectrowatindexpath.

then, can call performseguewithidentifier:sender: make dispatch_async call main thread.