index UITableView未加载图像

时间:2015-02-26 09:42:39

标签: ios objective-c uitableview

我在索引表中显示数据,如图所示,对于缩略图,我是通过排序数组的索引路径从照片数组中取出的。我正确地获取了照片名称,但它没有加载到TableViewCell

 NSString *sectionTitle = [IndexTitles objectAtIndex:indexPath.section];
  NSArray *sectionAnimals = [dictionaryIndex objectForKey:sectionTitle];
  NSString *cellText = [sectionAnimals objectAtIndex:indexPath.row];
  cell.name.text=cellText;

  NSUInteger indexofTheObject=[sortedLastName indexOfObject:cellText];
  NSString *photoString=[arrPhoto objectAtIndex:indexofTheObject];

  NSLog(@"photo %@",photoString);
  cell.imgView.image=[UIImage imageNamed:photoString];

index Table

2 个答案:

答案 0 :(得分:0)

您是否将图像添加到Images.xcassets?

如果没有,并且您正在直接从文件加载图片,那么您应该使用(在Swift中 - 抱歉!):

var boundle = NSBundle.mainBundle()

cell.imgView.image = UIImage(contentsOfFile: boundle.pathForResource("image", ofType: "png")!)

答案 1 :(得分:0)

NSString *sectionTitle = [IndexTitles objectAtIndex:indexPath.section];
NSArray *sectionAnimals = [dictionaryIndex objectForKey:sectionTitle];
cell.name.text = [sectionAnimals objectAtIndex:indexPath.row];


cell.imgView.image=[UIImage imageNamed:[arrPhoto objectAtIndex:indexPath.row]];