How can I load images from plist into UITableView?
I have saved videos and thumbnails in the Documents folder. And I gave the path to plist. In plist, I took an array and I added directories to the array. And in the dictionary I saved the image path
/Users/srikanth/Library/Application Support/iPhone Simulator/User/Applications/9E6E8B22-C946-4442-9209-75BB0E924434/Documents/image1
for the key image.
for video
/Users/srikanth/Library/Application Support/iPhone Simulator/User/Applications/9E6E8B22-C946-4442-9209-75BB0E924434/Documents/video1.mp4
for filePath.
I used the following code but it doesn't work. I am trying for images only. I need images to be loaded into a table in every 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 to images from plist.
But how can I extract the image from the path. NSLog output signal:
path: /Users/srikanth/Library/Application Support/iPhone Simulator/User/Applications/9E6E8B22-C946-4442-9209-75BB0E924434/Documents/snook.jpg
How can I get an image from it and store it in cell.imageView.image?
How can I make this work. Thanks.
+2
a source to share
1 answer
I see some problems in your code:
- When you instantiate a UITableViewCell you are creating a UIImageView
image2
that is unassigned and hence a memory leak. This not normal? - You don't need to get a reference to the cell's UIImageView by tag. UITableViewCell already has a UIImageView and its image can be set using the property
cell.imageView.image
.
Where do you download UIImage? You say you are saving the image path, but there is no code to load the image from that path.
0
a source to share