2014-07-03 46 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]]]; 
相關問題