【问题标题】:iOS: Couldn't compile connection: UIImageView in CelliOS:无法编译连接:单元格中的 UIImageView
【发布时间】:2012-05-31 19:22:36
【问题描述】:

我正在使用 NSXMLParser 解析 XML 文件。单元格的数量取决于 XML 文件有多少条目。这一切都很好。

现在我向我的原型单元添加了一个 UIImageView,我想在其中加载我的 URL(在 XML 文件中声明)。

我的故事板错误:无法编译连接..

我知道这是由于原型单元。但是如何将 UIImageView 添加到所有单元格中,可以显示来自 XML 的不同图像?

编辑:

这是我的代码,但这并不重要.. 每次我在 Interface Builder 中连接 UIImageView 时,都会出现错误..

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"productCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

XMLProductView *listedProduct = [appDelegate.products objectAtIndex:indexPath.row];

/*
NSOperationQueue *queue = [NSOperationQueue new];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] init];
[queue addOperation:operation];
*/

NSString *imageURL = listedProduct.image;

NSData *imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:imageURL]];

UIImage *image = [UIImage imageWithData:imageData];

[imageView setImage:image];

cell.textLabel.text = listedProduct.name;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

return cell;

}

【问题讨论】:

  • 我添加了我的代码,但我认为这不会导致错误。
  • 你的 imageView 添加到单元格了吗?
  • 是的,并且已连接。但是当我断开它时,错误消失了。我可以做我想做的事,图像不显示。

标签: ios xcode uiimageview cell


【解决方案1】:

也许您的 imageView 是一个出口?它不应连接到原型单元。您可以在程序中添加imageView:

 [cell addSubview:imageView];

或者在storyboard中创建imageView并通过:

 [cell viewWithTag:theTagOfImageView];

编辑 2

我认为这确实是您所需要的。祝你好运!

LazyTableImages

【讨论】:

  • 谢谢你的回答。我都试过了,但没有任何效果。我在 SO 上查看了一些帖子,发现了这个:stackoverflow.com/questions/9693595/…。但我不确定它是否有效。
  • @AlexisW 我认为它应该可以工作。因为我这样做没有问题。请仔细检查,并把你试过的代码:)
  • 好吧,我试过这个代码:UIImageView *imageView2 = (UIImageView *)[cell viewWithTag:1];imageView2.image = image;。但没有任何效果.___。''
  • @AlexisW 请在你的答案中添加一些代码并告诉我什么是“无效”?
  • 你好,代码在里面吗?我的问题:图像没有显示出来。
猜你喜欢
  • 1970-01-01
  • 2012-03-30
  • 2018-10-13
  • 1970-01-01
  • 1970-01-01
  • 2011-06-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多