2013-06-26 27 views
3

我這樣做:如何在UITableViewCell中顯示圖像來自NSMutableArray?

(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath { 

static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

if (cell == nil) { 

    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 

reuseIdentifier:CellIdentifier]; 

    cell.imageView.image = [UIImage imageNamed:[[self.articlesArray 

objectAtIndex:indexPath.row]objectForKey:@"images"]]; 

    // [cell.imageView setImageWithURL:[NSURL URLWithString:[[self.articlesArray 

objectAtIndex:indexPath.row]objectForKey:@"images"]]]; 


} 

return cell; 

} 

我這樣做:

cell.imageView.image = [UIImage imageNamed:[[self.articlesArray 

objectAtIndex:indexPath.row]objectForKey:@"images"]]; 

但沒有什麼是顯示在我的UITableViewCell

而且我想表現出對tableViewCell在左側左側圖像,

請告訴我,我怎麼能做到這一點。

+0

請確認'self.articlesArray'被初始化,每個條目都包含一個帶有「images」鍵的字典,key「images」指向一個NSString並且圖像存在於主包中因爲你使用'imageNamed:')。 – StatusReport

+0

yes self.articlesArray被初始化,並且每個條目都包含一個帶有指向NSString的鍵'images'的字典,如下所示:「http://www.dem......p-content/uploads/2011/05 /learn_t.jpg「 –

+0

您發佈的網址不完整。嘗試將'[UIImage imageNamed:]'的返回值設置爲一個變量,並通過調試來驗證它不是零。 – StatusReport

回答

1

我自己做過。

這裏是解決方案,它完美的工作。

NSData* imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString: 

[[self.articlesArray objectAtIndex:indexPath.row]objectForKey:@"images"]]]; 

UIImage* image = [[UIImage alloc] initWithData:imageData]; 

cell.imageView.image =image; 
相關問題