2012-03-20 17 views
0

誰でもperformSelectorInBackgroundでお手伝いできますか?私はperformSelectorInBackgroundの更新されたデータでテーブルをリロードしたい。IPhone + performselector in background

+8

バックグラウンドでのUI更新はありません。 UIの変更はメインスレッドで実行する必要があります。 – lukya

答えて

4

バックグラウンドスレッドでデータを取得するだけで、メインスレッドでデータを取得してテーブルビューを更新するとメインスレッドに戻ることができます。

- (UITableViewCell *)tableView:(UITableView *)tableView 
     cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    //All your views cell creations and other stuff 
    [self performSelectorInBackground:@selector(loadDataThatToBeFetchedInThread:) 
          withObject:objectArrayThatNeedToFetchData]; 
} 

- (void) loadDataThatToBeFetchedInThread:(NSArray *)objectThatNeedToFetchData 
{ 
    //Fetch the data here. which takes place in background thread 
    [self performSelectorOnMainThread:@selector(updateTableViewWithTheData:) 
          withObject:responseData 
         waitUntilDone:YES]; 
} 


- (void) updateTableViewWithTheData:(NSMutableArray *)yourData 
{ 
    //Update Data to tableview here 
} 
+0

申し訳ありません私は1つだけ+1を与えることができます:) –

+0

^ありがとう、私は確かにそれを試してみましょう – Shantanu

0

すべてのUI機能は、メインスレッドで実行する必要があります。したがって、メインスレッドのみでUITableViewをリロードする必要があります。

+0

素晴らしいコメントのように見えます!しかし、多分あなたはその質問を見ているかもしれません! –