1

ドキュメントディレクトリに異なるフォルダーがあり、各フォルダーに画像があります。ここで、別のフォルダーから 1 つの画像を表示したいと考えています。私は試しましたが、プログラムは行でクラッシュしています。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
//I dont know what put here for display from sqlite

    NSUInteger row = [indexPath row];

    cell.textLabel.text = [array1 objectAtIndex:row];
    //cell.detailTextLabel.text = [array2 objectAtIndex:row];
NSString *b = [array2 objectAtIndex:row];
NSLog(@"b=%@",b);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,     NSUserDomainMask, YES);
NSLog(@"%@",paths);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSError *error = nil;
NSArray *imageFileNames = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",b]] error:&error];
NSLog(@"file=%@",imageFileNames);

NSMutableArray *images = [[NSMutableArray alloc ] init];


for (int i = 0; i < [imageFileNames count]; i++)
{
    NSString *getImagePath = [documentsDirectory stringByAppendingPathComponent:[NSString     stringWithFormat:@"%@/%d.png",b, i]];
    UIImage *img = [UIImage imageWithContentsOfFile:getImagePath];
    [images addObject:img];
    NSLog(@"%@",getImagePath);
 }
NSLog(@"images=%@",images);



cell.imageView.image=[imageFileNames objectAtIndex:0];
//NSLog(@"row=%u",row);




return cell;


}
4

2 に答える 2

0

[UIImage imageNamed:@""]imageWithContentsOfFile ではなく画像に直接使用できます

于 2013-07-25T12:46:40.210 に答える