在我的项目中,我将图像保存到手机上的文档文件夹中,然后将它们加载到单独的 tableview 中。我取得了一些成功,拍摄的最后一张图像被加载到表中,但被加载到每一行而不是最后一个。这是我用来在 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];
}
}
这是正在发生的事情的一个例子:假设我拍了两张照片,一张叫做“10282012_13113138_image.jpg”,另一张叫做“10282012_13113468_image.jpg”。然后我去加载单元格中的图像,最后一张照片加载到两个单元格中。
任何帮助将非常感激!