2012-04-24 53 views
0

我在我的应用程序中使用了master-detail示例。HUD在执行segue时显示

我添加了MBProgressHUD显示加载屏幕,而细节得到加载。

的事情是,我不知道我在做什么错误的线程,但我已经结束了2种方式做的:

1 - 如果我不扔dispatch_async()时,HUD是延迟显示;

2 - 如果我在dispatch_async()内部执行segue,则需要花费更多时间来加载内容。

下面有例如1 DA代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    [HUD show:YES]; 
    [self performSegueWithIdentifier:@"detail" sender:nil]; 
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
} 

下面有例如2 DA代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    [HUD show:YES]; 
    dispatch_queue_t taskQ = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0); 
    dispatch_async(taskQ, ^{ 
     [self performSegueWithIdentifier:@"detail" sender:nil]; 
     [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
    }); 
} 

任何引线?

回答

0

这是为我工作的解决方案:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    HUD = [MBProgressHUD showHUDAddedTo:((AppDelegate*)[[UIApplication sharedApplication] delegate]).window.rootViewController.view animated:YES]; 
    HUD.labelText = @"Loading"; 
    HUD.labelFont = [UIFont systemFontOfSize:18]; 
    HUD.delegate = self; 
    [HUD showWhileExecuting:@selector(openYourNewView) onTarget:self withObject:nil animated:YES]; 
    }); 
} 

-(void)openYourNewView { 
    [self performSegueWithIdentifier:@"YourViewIdentifier" sender:self]; 
} 

不过,我还是以前的观点有些怪异的旋转,我不知道为什么。

0

我以某种方式解决了这个问题!

  1. 创建一个正常的方法,在那里你会调用progressHUD并调用第二

  2. 创建第二个方法,你做耗时东西的时间(加载视图)

  3. 上执行该方法主线程

样品:

-(void)callHUD { 

      [progressHUD show]; 

      dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 
       [self performSelectorOnMainThread:@selector(loadView) withObject:nil waitUntilDone:YES]; 
       dispatch_async(dispatch_get_main_queue(), ^{ 
      [progressHUD dismiss]; 
    }); 
}); 
} 

-(void)loadView { 
    //Perform your segue or transition which needs to load 
} 

希望能帮助别人寻找答案。 ;)干杯