In my project I am saving the images into the documents folder on my phone then i am loading them in a separate tableview. I am getting a bit of success, the very last image that is taken is loaded into the table, but is loaded into every row instead of just the last one. Here is the code i used to load the image in the tableview :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"List";
ListCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//Load PLIST
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [path objectAtIndex:0];
NSString *plistPath = [NSString stringWithFormat:@"%@/images.plist", documentsDirectory];
//Load PLIST into mutable array
NSMutableArray *imageArray = [NSMutableArray arrayWithContentsOfFile:plistPath];
for (NSDictionary *dict in imageArray) {
//Do whatever you want here, to load an image for example
NSString *imageFilePath = [NSHomeDirectory() stringByAppendingPathComponent:[dict objectForKey:@"Original Image"]];
UIImage *image = [UIImage imageWithContentsOfFile:imageFilePath];
[cell.imageofItem setImage:image];
}
}
Here is an example of what is happening
: Say i take 2 photos, one is called “10282012_13113138_image.jpg” and the other is called “10282012_13113468_image.jpg”. Then i go to load the images in the cell, and the last photo is loaded in the two cells.
Any help would be much appreciated!
Instead of
}
Try
The problem was that for each indexPath.row, you were iterating till the last element in the array, constantly overwriting the cell image until you get to the last image. Then for the next indexPath.row, you do the same thing, and setting that to the last image in the array, and so on….