【问题标题】:How to show images in UITableViewCell From NSMutableArray?如何从 NSMutableArray 在 UITableViewCell 中显示图像?
【发布时间】:2013-06-23 04:29:18
【问题描述】:

我正在这样做:

(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 左侧显示图像,

请告诉我该怎么做。

【问题讨论】:

  • 请确认 self.articlesArray 已初始化,每个条目都包含一个带有键“images”的字典,键“images”指向一个 NSString 并且图像存在于主包中(因为你使用imageNamed:)。
  • 是的 self.articlesArray 已初始化,每个条目都包含一个带有键“images”的字典,该字典指向一个像这样的 NSString “dem......p-content/uploads/2011/05/learn_t.jpg
  • 您发布的网址不完整。尝试将[UIImage imageNamed:]的返回值设置为一个变量,并通过调试验证它不是nil。

标签: uitableview uiimage nsmutablearray arrays


【解决方案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;

【讨论】:

    猜你喜欢
    • 2016-02-05
    • 1970-01-01
    • 1970-01-01
    • 2011-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-06
    • 1970-01-01
    相关资源
    最近更新 更多