0

アプリでマスター/ディテールの例を使用しています。

そして、MBProgressHUDを追加して、詳細が読み込まれている間に読み込み画面を表示しました。

問題は、スレッドで何が間違っているのかわからないということですが、それを行うには2つの方法があります。

1 - dispatch_async() をスローしないと、HUD が遅延して表示されます。

2 - dispatch_async() 内でセグエを実行すると、読み込みに必要以上の時間がかかります。

例 1 のコードは次のとおりです。

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

例 2 のコードは次のとおりです。

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

手がかりはありますか?

4

2 に答える 2

0

私は何とかこれを回避する方法を管理しました!

  1. progressHUD を呼び出して 2 つ目のメソッドを呼び出す通常のメソッドを作成します。

  2. 時間のかかる作業 (ビューの読み込み) を行う 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
}

答えを探している他の人に役立つことを願っています。;) 乾杯

于 2015-03-07T03:55:23.637 に答える