私のプロジェクトでは、画像を携帯電話のドキュメント フォルダーに保存してから、別のテーブルビューに読み込んでいます。少し成功しています。最後に取得した画像がテーブルに読み込まれますが、最後の画像だけでなくすべての行に読み込まれます。テーブルビューに画像をロードするために使用したコードは次のとおりです。
- (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];
}
}
何が起こっているかの例を次に示します。2 枚の写真を撮るとします。次に、セルに画像をロードすると、最後の写真が 2 つのセルにロードされます。
どんな助けでも大歓迎です!