views:

278

answers:

1

I have stored the videos and the thumbnail images of the videos in Documents folder. And I have given the path in plist. In plist I took an array and I added directories to the array. And in the dictionary I stored the image path

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

for key imagePath.

for video

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

for key filePath.

I used following code but it is not working. I am trying only for images. I need the images to be loaded in the table in each cell.

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

I got the path of the images are from the plist.
But, how can I extract the image from the path.
The output od NSLog: is

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

How can I get the image from it and store in cell.imageView.image ?
How can I make this work. Thank you.

A: 

I see some problems in your code:

  • When you are creating the UITableViewCell instance, you create an UIImageView image2 that is not assigned and therefore leaks memory. Is not normal ?
  • You do not need to get a reference to the UIImageView of the cell by tag. An UITableViewCell already has an UIImageView and its image can be set with the cell.imageView.image property.

Where are you loading the UIImage ? You say you are storing the image path, but there is no code for loading image from this path.

Laurent Etiemble
I thought that passing key value of the dictionary in plist gives the path. My mistake. I stored the path in the dictionary in plist for key value imagePath. How can we get the path from the plist in to our code? I will check my code and correct it.Thank You.
srikanth rongali
I got the path of the image. but how to get the image from it ?Th path ispath: /Users/srikanth/Library/Application Support/iPhone Simulator/User/Applications/9E6E8B22-C946-4442-9209-75BB0E924434/Documents/snook.jpgHow to show the image snook.jpg from the path in cell ?
srikanth rongali
Use the "imageWithContentsOfFile:" method of UIImage:UIImage *img = [UIImage imageWithContentsOfFile:path];
Laurent Etiemble
I did it but it is not working. It is not showing images in the cell.When I debugged, img is showing as 0*0. Any suggestions please ?Thank you.
srikanth rongali
Thank You very much Laurent sir. I got the correct solution finally. And I messed all my time without clear knowledge of what I need and what I should do. Now, I kept the images in the Documents folder and the file name in plist. I accessed it with this file name. I used UIImage property you suggested me. Now I got the images in my table cell.Thank You.
srikanth rongali