【发布时间】: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