2014-07-03 48 views
0

我正在创建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; 
} 

在此先感谢。

+0

第一次加载此链接的图像数据“http://122.182.130.142:9090/abc/abc/abc.jpg”并将其转换为图像,然后设置为图像 – Yogendra

回答

2

试试这一行。

UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:MyURL]]]; 
相关问题