如何从服务中设置图像并在表格单元格中显示?

时间:2014-07-03 06:59:24

标签: ios iphone

我正在创建Iphone应用程序以从其余的api获取图像并在表格单元格中显示图像。我使用了以下代码。但它不起作用。 任何人都可以帮我这样做。

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
[cell.textLabel setLineBreakMode:NSLineBreakByWordWrapping];
[cell.textLabel sizeToFit];

if(cell == nil)
{
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.imageView.image = [UIImage imageNamed:"http://122.182.130.142:9090/abc/abc/abc.jpg"];
cell.textLabel.text = [NSString stringWithFormat:[message objectAtIndex:0], indexPath.row];
return cell;
}

提前致谢。

1 个答案:

答案 0 :(得分:2)

试试这一行。

UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:MyURL]]];