如何使用shouldPerformSegueWithIdentifier在正确的时间显示hud?

时间:2015-03-12 07:22:11

标签: ios objective-c

背景

  1. 导航控制器视图
  2. 包含具有ftp信息的单元格的表
  3. Cell segue将连接到ftp服务器并显示列表
  4. shouldPerformSegueWithIdentifier将检查服务器的连接状况是否
  5. 如果它能够连接到ftp服务器,它将执行prepareForSegue
  6. 单击一个单元格时,我正在显示HUD并显示“正在连接...”,当它验证时,请按下一页。

    问题:HUD不会立即显示并在推送到下一个视图之前显示。为了以防万一,尝试各种不同的HUD,但失败了。我确信这不是HUD。

    问题:如何点击单元格立即启动HUD? shouldPerformSegueWithIdentifier是一个正确的地方开始显示HUD吗?我尝试使用dispatch_async或同步但我必须返回YES / NO才能执行segue或不执行。

    -(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];
        }
    }
    

1 个答案:

答案 0 :(得分:1)

您可以从tableView:didSelectRowAtIndexPath:协议实施UITableViewDelegate。当用户点击单元格时,此方法被调用。然后,您必须检查此单元格是否应触发您的hud(假设您有不同类型的单元格,否则您可以省略检查)。

-(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];

   } 
}