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

答えを探している人を助けることを望みます。 ;)乾杯

関連する問題