将图像分配给tableview单元格

时间:2011-11-21 18:11:44

标签: iphone ios5

我试图在表格单元格中的imageView中显示图像。图像名称我从Web服务中提取,然后将其放在对象的NSString类型属性中。

//Get image corresponding to row index from array
Visitors *tmp = [allItems objectAtIndex:[indexPath row]];

//This works perfectly


     [[cell textLabel] setText:[tmp fName]];
        [[cell detailTextLabel] setText:[tmp flagName]];



    NSString *pathToImage = [tmp flagName];

//This prints correct image file name, like usflag.gif
   NSLog(@"%@ ",pathToImage);

//This shows images in each cell
    cell.imageView.image =[UIImage imageNamed:@"usflag.gif"];

//This shows nothing
    cell.imageView.image =[UIImage imageNamed:pathToImage];

有人可以解释为什么它无法读取图像以及使其正常工作的正确方法。

谢谢。

1 个答案:

答案 0 :(得分:0)

您的错误很可能与您的图片名称有关。如果在应用程序包中找到同名图像文件,imageNamed将仅返回图像。如果存在这些图像文件,请检查每一个。小心拼写。