0

3つのインデックス(名前、日付、ID)で並べ替える必要のあるアイテムの長いリストを表示しています。次に、self.navigationItem.titleViewにUISegmentControlを使用してリストを表示します。ユーザーはそのコントロールを使用して、表示する並べ替え順序を選択できます。ユーザーは、いくつかのカテゴリに基づいてそのリストをフィルタリングするオプションがあります。次に、リストを再度並べ替える必要があります。これは、新しいフィルター処理されたリストでは、名前が1つしか表示されない可能性があるため、名前で並べ替え順序を表示したくないためです。したがって、UISegmentControlをリセットできるようにするためだけにソートする必要があります。ソートには数秒かかるので、別のスレッドにプッシュしました。これが私のコードです:

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:@"value"]) {
    //The filter value has changed, so I have to redo the sort

        [[self navigationItem] setTitleView:NULL];
        [[self navigationItem] setTitle:@""];
        self.navigationItem.rightBarButtonItem.enabled = false;
        [self.tableView reloadData]; //I reload here because I want to display Loading... on my table (another var has been set before hands so the tableview will display that)

        dispatch_async(backgroundQueue, ^(void) {
            [self displayAfterFilterChanged];  
        });
}
}

-(void) displayAfterFilterChanged
{
displayState = DISPLAYRUNNING;
[self setupSort];  //<<< this is where the 3 sort index are setup based on the filter
dispatch_async(dispatch_get_main_queue(), ^(void) {  //<<< I call all the UI stuff in the main_queue. (remember that this method has been call from dispatch_async)
    [self.tableView reloadData]; //<< the table will display with the sorted and filtered data 
    self.navigationItem.rightBarButtonItem.enabled = true;
    if (!self.leSelecteur) { //<<< if I don't have a UISegmentControl I display a title text
        [[self navigationItem] setTitle:@"atitle"];
    } else { // I have a UISegmentControl, so I use it. 
        [[self navigationItem] setTitleView:self.leSelecteur];
        NSLog(@"before setneedsdisplay");
        [self.navigationItem.titleView setNeedsDisplay];
        NSLog(@"after setneedsdisplay");
    }
});
}

現在、問題:テーブルはすぐに再表示され、rightbarbuttonitemがすぐに有効になります。ただし、navigationItem titleViewは、それ自体が表示されるまでに5〜10秒かかります。表示サイクルをスキップして次のサイクルをキャッチしているようです。スピードアップする方法はありますか?「setNeedsdisplayの前」と「setneedsdisplayの後」がすぐにログに表示されていることがわかります。ただし、実際の更新は5〜10秒後に行われます。

4

3 に答える 3

0

UI コードはメイン スレッドで実行する必要があります。別のスレッドを作成して、UI でタスクを実行しないでください。

于 2012-05-04T19:29:29.280 に答える
0

displayAfterFilterChanged の dispatch_async(dispatch_get_main_queue(), ^(void) { を dispatch_sync(dispatch_get_main_queue(), ^(void) { に変更してみてください[self setupSort]; をブロックしてから、すべての UI コードを UI スレッドで同期的に実行する必要があると仮定します。

于 2012-05-04T19:27:56.377 に答える