1

Background

  1. Navigation Controller View
  2. Table with cells having ftp information
  3. Cell segue will connect to ftp server and show lists
  4. shouldPerformSegueWithIdentifier will check if server's connection condition
  5. if it's able to connect to the ftp server, it it will perform prepareForSegue

When a cell is clicked, I am showing HUD with "connecting..." and when it verifies, push to next page.

Problem : HUD doesn't show up right away and shows right before it's pushing to next view. Tried with various different HUD just in case, but fails. I am sure it's not the HUD.

Question : How can I start HUD right away upon click cell? Is shouldPerformSegueWithIdentifier a right place to start show HUD? I tried with dispatch_async or sync but I have to return YES/NO to should perform segue or not.

-(BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
{
    if([identifier isEqual:@"ConnectServer"])
    {
        self.HUD = self.prototypeHUD;
        self.HUD.textLabel.text = @"Connecting...";
        [self.HUD showInView:self.navigationController.view];
    NSManagedObject *obj = self.serverList[[self.tableView indexPathForSelectedRow].row];
        return [self checkServerConnection:obj];
    }
}
handicop
  • 892
  • 12
  • 25
  • you can implement `didSelectRowAtIndexPath:`: – nburk Mar 12 '15 at 07:28
  • @nburk, let me try and get back here. Thanks. – handicop Mar 12 '15 at 07:29
  • were you able to solve the issue? @handicop – nburk Mar 12 '15 at 08:50
  • @nburk no I haven't able to solve the issue yet. I will try your suggestion of "deleting segue from storyboard and trigger manually" later since I have to change other stuff as it's on navigation controller and deleting segue from storyboard won't show some stuff on xcode storyboard editor(eg toolbar with nav controller). – handicop Mar 12 '15 at 08:56
  • ok, let me know if you need some help :) – nburk Mar 12 '15 at 09:09
  • did it work for you by now? @handicop – nburk Mar 13 '15 at 06:42
  • i ended up with changing the process and now it's working. For the new process, I took your advice of trigger segue manually, and added dispatch_async to process login and then async to update ui. – handicop Mar 13 '15 at 07:56

1 Answers1

1

You can implement tableView:didSelectRowAtIndexPath: from the UITableViewDelegate protocol. This method gets called right when the user taps on a cell. You will then have to perform a check whether this cell should trigger your hud (assumed you have different kinds of cells, otherwise you can omit the check).

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
   if (<check if the appropriate cell was tapped>) {
       self.HUD = self.prototypeHUD;
       self.HUD.textLabel.text = @"Connecting...";
       [self.HUD showInView:self.navigationController.view];

   } 
}
nburk
  • 22,409
  • 18
  • 87
  • 132
  • when I add didSelectRowAtIndexPath and cell clicked, it flows shouldPerformSegueWithIdentifier, prepareforsegue, and then didselectrow. Is it possible to change the method execution order? – handicop Mar 12 '15 at 07:36
  • hmm I don't think so unfortunately... these methods are alle invoked automatically by iOS, so you won't be able to change this flow. also it would't make sense to call `shouldPerformSequeWithIdentifier` **after** `prepareForSegue`. I answered a related question a while ago: http://stackoverflow.com/questions/26946566/calling-performseguewithidentifier-doesnt-call-shouldperformseguewithidentifier/26946596#26946596 – nburk Mar 12 '15 at 07:54
  • 1
    however, what you can do is **delete the segue from storyboard** and **trigger it manually**, or even don't use a segue and rather instantiate the destination view controller yourself (`[self.storyboard instantiateViewController...]``) and use `[self.navigationController pushViewController:destViewController]` – nburk Mar 12 '15 at 07:54