2010-04-23 74 views
2

我已將視頻的視頻和縮略圖圖像存儲在「文檔」文件夾中。我已經在plist的路上。在plist中,我使用了一個數組,並向數組添加了目錄。 而在我的字典存儲關鍵的ImagePath圖像路徑如何將圖像從plist加載到UITableView中?

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

視頻

/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]]; 
} 

我得到的圖像的路徑是從plist。
但是,如何從路徑中提取圖像。
輸出OD的NSLog:是

path: /Users/srikanth/Library/Application Support/iPhone Simulator/User/Applications/9E6E8B22-C946-4442-9209-75BB0E924434/Documents/snook.jpg 

如何從它和存儲獲得的圖像cell.imageView.image?
我該如何做這項工作。 謝謝。

回答

0

我看到你的代碼的一些問題:

  • 當你創建的UITableViewCell實例,您創建一個的UIImageView image2不分配,因此出現內存泄漏。不正常嗎?
  • 您不需要通過標記獲取對單元格的UIImageView的引用。一個UITableViewCell已經有一個UIImageView,它的圖像可以通過cell.imageView.image屬性來設置。

你在哪裏加載UIImage?您說您正在存儲圖像路徑,但沒有用於從此路徑加載圖像的代碼。

+0

我認爲在plist中傳遞字典的鍵值給出了路徑。我的錯。我將該路徑存儲在字典中的鍵名爲imagePath的plist中。我們如何才能從plist到我們的代碼?我會檢查我的代碼並更正它。 謝謝。 – 2010-04-23 08:37:01

+0

我得到了圖像的路徑。但如何從中獲得圖像? Th path is path:/ Users/srikanth/Library/Application Support/iPhone Simulator/User/Applications/9E6E8B22-C946-4442-9209-75BB0E924434/Documents/snook.jpg 如何顯示圖像snook.jpg細胞中的路徑? – 2010-04-23 09:47:29

+1

使用UIImage的「imageWithContentsOfFile:」方法: UIImage * img = [UIImage imageWithContentsOfFile:path]; – 2010-04-23 11:17:31

相關問題