开发者

iphone how to access a custom cell outside of cellForRowAtIndexPath

i have set up a tableview with custom cells. customCell is a class. heres the code for a more accurate view:

    - (UITableView开发者_如何学运维Cell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

 NSManagedObject *object = (NSManagedObject *)[entityArray objectAtIndex:indexPath.row];

 NSString *cellIdentifier = [NSString stringWithFormat:@"asd%d", indexPath.row];

 customCell *cell = [[tableView dequeueReusableCellWithIdentifier:cellIdentifier] autorelease];
 //i tried setting a tag but dunno how to call it afterwards
     [cell setTag:indexPath.row];

 if (cell == nil) {
        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"customCell" owner:self options:nil];
  cell = [topLevelObjects objectAtIndex:0];
    }

 if (cell.imagen != nil) {
  [[cell imageView] setImage:[cell imagen]];
 } else { /* setup image... */ }
    }


    -(void) webImageReady:(WebImage *)downloadedImage imageView:(UIImageView *)imageView cellTag:(NSInteger *)cTag
    { 
     // This is the part where i want to access cell.imagen, this is actually wrong...
     [[[imageView.superview viewWithTag:cTag] imagen] setImagen:downloadedImage.Image];
     [imageView setImage:downloadedImage.Image];

    }

Ok. now i want to access (reference) the cell.imagen property from a method outside cellForRowAtIndexPath, more precisely at a selector for a download finished (delegated) Thanks in advance!


Do it inside cellForRowAtIndexPath if the image is downloaded, and on successful download of the image do [tableview setNeedsDisplay]


You shouldn't refer to the cell outside the cell creation method, you should consider the case the cell was rendered but while getting the image was scrolled out the dealloced or even reused for another cell, one way to solve it is to have image view array or something similar.

I think you should try using a third party lib that already doing it(among other things) called Three20. It have an object call TTImageView that gets a URL and loads it in the background, it solves all of the cases along with optimized caching

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜