2012-04-24 49 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 
} 

希望能幫助別人尋找答案。 ;)乾杯