2012-03-26 8 views
0

didselectCellFromIndexPathメソッドのセル上にアクティビティインジケータを表示する方法を忘れていますか?セル選択のアクティビティインジケータアニメーション

基本的には、私は、私の解析クラスからの戻り値を取得したら、私はアニメーションを停止し、ダニと置き換えて、選択したから活動指標のアニメーションを開始したい。 didselectcellメソッドの中でこれを行う方法がわからないのですか?これは私が使用するコードです。 didSelectRowAtIndexPath:

cellActivityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 
     [cell setAccessoryView:cellActivityIndicator]; 
//then 
[cellActivityIndicator startAnimating]; 
//then 
[cellActivityIndicator stopAnimating]; 

は、しかし、私はちょうどindexPath内でそれを行うにはいくつかのアドバイスを必要とする方法

答えて

2

をごdidSelectRowAtIndexPath方法では、使用してセル自体にアクセスすることができます。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 

    //Initialise, add to cell's view and start your activity indicator 

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 

     //Call your function or whatever work that needs to be done 
     //Code in this part is run on a background thread 

     dispatch_async(dispatch_get_main_queue(), ^(void) { 
      //Stop your activity indicator 
      //Code here is run on the main thread 
     }); 
    }); 
} 

これをメソッドはlibdispatch/Grand Central Dispatchを使い、あなたにはiOS 4以上が必要です。

+0

ありがとうございました。 –

+0

No buddy – sooper

+0

これは2日間の検索と多くの試行錯誤を終えた - ありがとう! – resedasue

2
dispatch_queue_t queue = dispatch_queue_create("Downloading image", NULL); 

dispatch_async(queue, ^{ 
    NSURL *url = [NSURL URLWithString:@"http://store.storeimages.cdn-apple.com/2441/as-images.apple.com/is/image/AppleInc/step0-edu-pricing?wid=264&hei=144&fmt=png-alpha&qlt=95"]; 

    cellActivityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 
    [cell setAccessoryView:cellActivityIndicator]; 

    NSData *downloadedImage = download data; 

    // update your UI screen 
    dispatch_async(dispatch_get_main_queue(), ^{ 
     [subViewActivityIndicator removeFromSuperview]; 
     [cell setAccessoryView:something]; 
    }); 
}); 
dispatch_release(queue); 
関連する問題