1

プログラムの実行中に動的に新しい行を追加するUITableViewがあります。私は常に新しい行を一番下に追加します。その場合、テーブルビューを一番下までスクロールして、新しい行を表示します。

NSInteger oldCount = [self.game count];
dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
    //This may take a long time
    BOOL gameStateChanged = [self.game update] ;
    dispatch_async( dispatch_get_main_queue(), ^{
        if (gameStateChanged)
        {
            NSMutableArray* ipaths = [NSMutableArray arrayWithCapacity:5];
            NSInteger newCount = [self.game count];
            for (NSInteger i = oldCount; i < newCount; i++)
            {
                [ipaths addObject:[NSIndexPath indexPathForRow:i inSection:0]];
            }
            NSIndexPath* ipath = [ipaths lastObject];
            [self.wordsTableView insertRowsAtIndexPaths:ipaths 
                                       withRowAnimation:UITableViewRowAnimationNone];
            [self.wordsTableView scrollToRowAtIndexPath: ipath 
                                       atScrollPosition:UITableViewScrollPositionBottom 
                                               animated:YES];
        }
    });
});

問題は、時々スクロールを停止することです。スクロールを停止した後、ユーザーがテーブルビューを手動でスクロールしない限り、同じメソッドへの後続の呼び出しで自動的にスクロールを開始しません。

スクロール、送信のアニメーションをオフにすると、animated:NO完全に機能します。どうすればいいの?そして、どうすればアニメーションを使用してそれを機能させることができますか?

4

1 に答える 1

0

メソッドを呼び出すときは、完了するまで待ってみてください...別の可能性として、animation:no 関数をアニメーション ブロックに統合することもできます...</p>

そんな感じ:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];

[self.wordsTableView scrollToRowAtIndexPath: ipath 
                                       atScrollPosition:UITableViewScrollPositionBottom 
                                               animated:NO];

[UIView commitAnimations];

これは実際には最善の解決策ではありませんが、役立つかもしれません…</p>

于 2012-09-19T09:39:20.033 に答える