2012-03-26 28 views
0

我在研究如何从didselectCellFromIndexPath方法显示单元格上的活动指示符?来自单元格选择的活动指标动画

基本上我想从did选择开始活动指标动画,然后一旦我从解析类中得到一个返回,我将停止动画并用勾号替换。但我不知道如何在didselectcell方法内做到这一点?这是我会使用的代码。

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

,但我只需要做好这里面indexPath一些建议:didSelectRowAtIndexPath方法:方法

回答

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

非常感谢您的工作。 – 2012-03-27 00:03:22

+0

没问题的朋友 – sooper 2012-03-27 00:26:24

+0

这结束了两天的搜索和很多反复试验 - 谢谢! – resedasue 2012-08-07 01:05:59

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); 
相关问题