2012-03-26 3 views
0

didselectCellFromIndexPath 메소드에서 셀에 활동 표시기를 표시하는 방법을 wounding하고 있습니까?셀 선택에서 활동 표시기 애니메이션

기본적으로 나는 활동 분류기 애니메이션을 시작하고 싶습니다. 그런 다음 파싱 클래스에서 돌아 오면 애니메이션을 멈추고 진드기로 바꿉니다. 그러나 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 problem 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);