繁体   English   中英

iPhone如何访问cellForRowAtIndexPath之外的自定义单元格

[英]iphone how to access a custom cell outside of cellForRowAtIndexPath

我已经用自定义单元格设置了一个tableview。 customCell是一个类。 继承人代码以获得更准确的视图:

    - (UITableViewCell *)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];

    }

好。 现在,我想从cellForRowAtIndexPath外部的方法访问(引用)cell.imagen属性,更确切地说,是在选择器中完成下载(委托),谢谢!

如果已下载图像,请在cellForRowAtIndexPath内部执行,并在成功下载图像后执行[tableview setNeedsDisplay]

您不应该在单元格创建方法之外引用单元格,而应考虑单元格被渲染的情况,但是在获取图像时将其滚动到其他单元格的重新分配甚至重用的情况下,一种解决方法是拥有图像视图数组或类似的东西。

我认为您应该尝试使用已经做过的第三方库(除其他功能外)称为Three20。 它有一个对象调用TTImageView,该对象获取URL并将其加载到后台,它解决了所有情况,并优化了缓存

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM