iphone - MBProgressHUD activity indicator doesn't show in viewDidAppear after segue is performed -


i have 2 uitableviewcontrollers , b, , i'm trying when click on table view cell in a:

  1. prepare segue b setting of b's variables a.
  2. perform segue b.
  3. b appears.
  4. display "loading" activity indicator [mbprogresshud][1].
  5. in background task, retrieve data url.
  6. if error occurs in url request (either no data received or non-200 status code), (a) hide activity indicator, (b) display uialertview error message
  7. else, (a) reload b's tableview retrieved data, (b) hide activity indicator

however, what's happening, , don't know how fix it:

  1. after clicking cell in a, b slides in right empty plain uitableview. mbprogresshud does not show.
  2. after while, tableview reloads retrieved data, mbprogresshud appearing briefly.
  3. the mbprogresshud disappears.

there doesn't seem error way background task performed. problem is, how display mbprogresshud activity indicator b view controller appears? (and actually, how come it's not showing?) code below.

a's prepareforsegue

- (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender {     b *b = (b *)[segue destinationviewcontroller];      // set of b's variables here... } 

relevant methods in b

- (void)viewdidappear:(bool)animated {     [self startover]; }  - (void)startover {     [self displayloadinganddisabletableviewinteractions];     [self retrievelistings];     [self.tableview reloaddata];     [self hideloadingandenabletableviewinteractions]; }  - (void)displayloadinganddisabletableviewinteractions {     mbprogresshud *hud = [mbprogresshud showhudaddedto:self.view animated:yes];     hud.labeltext = @"loading";     [uiapplication sharedapplication].networkactivityindicatorvisible = yes;      self.tableview.userinteractionenabled = no; }  - (void)hideloadingandenabletableviewinteractions {     [mbprogresshud hidehudforview:self.view animated:yes];     [uiapplication sharedapplication].networkactivityindicatorvisible = no;      self.tableview.userinteractionenabled = yes; }  - (void)retrievelistings {     __block nsarray *newsearchresults;      // perform synchronous url request in thread.     dispatch_sync(dispatch_get_global_queue(dispatch_queue_priority_default, 0), ^{         newsearchresults = [self fetchnewsearchresults];     });      // if nil returned, there must have been error--display uialertview.     if (newsearchresults == nil) {         [[[uialertview alloc] initwithtitle:@"oops!" message:@"an unknown error occurred. try again later?" delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil] show];     } else {         // add retrieved data uitableview's model. then,         [self.tableview reloaddata];     } }  - (nsarray *)fetchnewsearchresults {     // assemble nsmutablearray called newsearchresults nsurlconnection data.     // return nil if error or non-200 response code occurred.     return newsearchresults; } 

i think have call [self hideloadingandenabletableviewinteractions]; after newsearchresults = [self fetchnewsearchresults]; retrieving data in thread means -startover continue executing after calling [self retrievelistings]; , hide hud right away. because updating display have make sure doing on main thread. see example

dispatch_async(dispatch_get_main_queue(), ^{             //update ui here         }); 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -