Cocoa touch 如何将图像从plist加载到UITableView?

Cocoa touch 如何将图像从plist加载到UITableView?,cocoa-touch,iphone-sdk-3.0,uitableview,uiimageview,Cocoa Touch,Iphone Sdk 3.0,Uitableview,Uiimageview,我已将视频和视频的缩略图存储在Documents文件夹中。我已经用plist给出了路径。在plist中,我获取了一个数组,并将目录添加到该数组中。 在字典里我存储了图像路径 /Users/srikanth/Library/Application Support/iPhone Simulator/User/Applications/9E6E8B22-C946-4442-9209-75BB0E924434/Documents/image1 对于键imagePath 视频 /Users/srik

我已将视频和视频的缩略图存储在Documents文件夹中。我已经用plist给出了路径。在plist中,我获取了一个数组,并将目录添加到该数组中。 在字典里我存储了图像路径

/Users/srikanth/Library/Application Support/iPhone Simulator/User/Applications/9E6E8B22-C946-4442-9209-75BB0E924434/Documents/image1  
对于键imagePath

视频

/Users/srikanth/Library/Application Support/iPhone Simulator/User/Applications/9E6E8B22-C946-4442-9209-75BB0E924434/Documents/video1.mp4
用于密钥文件路径

我使用了以下代码,但它不起作用。我只是尝试图像。我需要将图像加载到每个单元格的表中

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) 
    {
       cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];

        [cell setAccessoryType:UITableViewCellAccessoryDetailDisclosureButton];
        UIImageView *image2;
        image2.frame = CGRectMake(0.0f, 0.0f, 80.0f, 80.0f);
        image2.backgroundColor = [UIColor clearColor]; 

    }
    NSDictionary *dictOfplist = [cells objectAtIndex:indexPath.row];
    NSString *path = [dictOfplist objectForKey:@"imagePath"];
    NSLog("path: %@", path);
    return cell;
}  

- (void)viewDidLoad 
{
    [super viewDidLoad];
    self.title = @"Library";
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Close" style:UIBarButtonItemStyleBordered target:self action:@selector(close:)];

    NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"details" ofType:@"plist"];
    contentArray = [NSArray arrayWithContentsOfFile:plistPath];

    cells = [[NSMutableArray alloc]initWithCapacity:[contentArray count]];

    for(dCount = 0; dCount < [contentArray count]; dCount++)
        [cells addObject:[contentArray objectAtIndex:dCount]];
}
如何从中获取图像并存储在cell.imageView.image中?
我怎样才能做到这一点。
谢谢。

我发现您的代码中存在一些问题:

  • 创建UITableViewCell实例时,会创建未分配的UIImageView
    image2
    ,因此会泄漏内存。这不正常吗
  • 您不需要通过标记获取对单元格UIImageView的引用。UITableViewCell已具有UIImageView,可以使用
    cell.imageView.image
    属性设置其图像

你在哪里加载UIImage?您说您正在存储图像路径,但没有从该路径加载图像的代码。

我发现您的代码中存在一些问题:

  • 创建UITableViewCell实例时,会创建未分配的UIImageView
    image2
    ,因此会泄漏内存。这不正常吗
  • 您不需要通过标记获取对单元格UIImageView的引用。UITableViewCell已具有UIImageView,可以使用
    cell.imageView.image
    属性设置其图像

你在哪里加载UIImage?您说您正在存储图像路径,但没有从该路径加载图像的代码。

我认为在plist中传递字典的键值会给出路径。我的错误。我在plist中为键值imagePath存储了字典中的路径。我们如何获得从plist到代码的路径?我将检查我的代码并更正它。谢谢,我找到了图像的路径。但是如何从中获得图像呢?路径是路径:/Users/srikanth/Library/Application Support/iPhone Simulator/User/Applications/9E6E8B22-C946-4442-9209-75BB0E924434/Documents/snook.jpg如何从单元格中的路径显示图像snook.jpg?使用UIImage的“imageWithContentsOfFile:”方法:UIImage*img=[UIImage imageWithContentsOfFile:path];我做了,但不起作用。它不在单元格中显示图像。当我调试时,img显示为0*0。有什么建议吗?谢谢,非常感谢,劳伦特先生。我终于找到了正确的解决办法。我把所有的时间都搞得一团糟,不清楚我需要什么,我应该做什么。现在,我将图像保存在Documents文件夹中,文件名保存在plist中。我用这个文件名访问了它。我使用了你建议的UIImage属性。现在我把图像放在我的桌子上。谢谢。我认为在plist中传递字典的键值会给出路径。我的错误。我在plist中为键值imagePath存储了字典中的路径。我们如何获得从plist到代码的路径?我将检查我的代码并更正它。谢谢,我找到了图像的路径。但是如何从中获得图像呢?路径是路径:/Users/srikanth/Library/Application Support/iPhone Simulator/User/Applications/9E6E8B22-C946-4442-9209-75BB0E924434/Documents/snook.jpg如何从单元格中的路径显示图像snook.jpg?使用UIImage的“imageWithContentsOfFile:”方法:UIImage*img=[UIImage imageWithContentsOfFile:path];我做了,但不起作用。它不在单元格中显示图像。当我调试时,img显示为0*0。有什么建议吗?谢谢,非常感谢,劳伦特先生。我终于找到了正确的解决办法。我把所有的时间都搞得一团糟,不清楚我需要什么,我应该做什么。现在,我将图像保存在Documents文件夹中,文件名保存在plist中。我用这个文件名访问了它。我使用了你建议的UIImage属性。现在我把图像放在我的桌子上。非常感谢。
path: /Users/srikanth/Library/Application Support/iPhone Simulator/User/Applications/9E6E8B22-C946-4442-9209-75BB0E924434/Documents/snook.jpg