【发布时间】:2014-07-28 15:29:13
【问题描述】:
我有一个 json 数组,我正在使用以下内容来检索数据:
- (void) retrieveData
{
NSURL * url = [NSURL URLWithString:getDataURL];
NSData * data = [NSData dataWithContentsOfURL:url];
jsonArray = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
//set up cities array
dronesArray = [[NSMutableArray alloc] init];
//Loop json array
for (int i = 0; i < jsonArray.count; i++)
{
//Create city/drone object
NSString * dID = [[jsonArray objectAtIndex:i] objectForKey:@"id"];
NSString * dName = [[jsonArray objectAtIndex:i] objectForKey:@"droneName"];
NSString * dPic = [[jsonArray objectAtIndex:i] objectForKey:@"dronePic"];
[dronesArray addObject:[[City alloc]initWithDroneName:dName andDronePic:dPic]];
}
}
上面显示单元格很好:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
City * droneObject;
droneObject = [dronesArray objectAtIndex:indexPath.row];
cell.textLabel.text = droneObject.droneName;
//Accessory
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
但它只显示名称,没有图像。图像以 URL 格式存储,例如http://www.domain.com/image.jpg 在 sql 数据库中。如何导入图像以使其看起来像这种格式:
好的,所以我在 cellforrowatindexpath 中添加了以下代码,但它什么也没做:
[[cell imageView] setImage: [UIImage imageNamed:droneObject.dronePic]];
【问题讨论】:
-
首先弄清楚如何从文件中显示一个图像。然后是来自 URL 的一张图片。然后弄清楚多张图片的事情。
-
您对 imageView 没有任何参考。你在使用故事板吗?
-
以您提到的方式设置图像 (
+imageNamed:) 意味着您已下载该图像或在某处的捆绑包中。在您的情况下,您所拥有的只是 URL。您需要从该 URL 下载图像。
标签: ios json uitableview uiimage