1

カメラショットからドキュメントディレクトリに保存しているjpg画像がいくつかあります。ドキュメントディレクトリですべてのjpg画像を検索し、それらを配列にロードして、オーバーフロービューに表示できるようにします。

これは、documentsディレクトリでjpg画像を見つけて並べ替えるための私のコードです。

   NSString *extension = @"jpg";
        NSFileManager *fileManager = [NSFileManager defaultManager];



        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];

        NSArray *contents = [fileManager contentsOfDirectoryAtPath:documentsDirectory error:nil];  
        NSMutableArray *jpegFiles = [NSMutableArray arrayWithCapacity: [contents count]];

       NSString *filename;
        for (filename in contents)

        {
            if ([[filename pathExtension] isEqualToString:extension]) 
                     {
             [jpegFiles addObject:[UIImage imageNamed:[documentsDirectory stringByAppendingPathComponent:filename]]];


            }
        }

    // Add the coverflow view
    coverflow = [[TKCoverflowView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
    coverflow.coverflowDelegate = self;
    coverflow.dataSource = self;
    [self.view addSubview:coverflow];
    [coverflow setNumberOfCovers:6];

- (void) coverflowView:(TKCoverflowView*)coverflowView coverAtIndexWasBroughtToFront:(int)index{
        NSLog(@"Front %d",index);
}

- (TKCoverflowCoverView*) coverflowView:(TKCoverflowView*)coverflowView coverAtIndex:(int)index{


    TKCoverflowCoverView *cover = [coverflowView dequeueReusableCoverView];

    if(cover == nil){
        // Change the covers size here
        cover = [[TKCoverflowCoverView alloc] initWithFrame:CGRectMake(0, 0, 280, 210)]; // 224
        cover.baseline = 200;

    }
    cover.image = [covers objectAtIndex:index % [covers count]];

    return cover;

}

私は考えられるすべてを試しましたが、何も機能しません。

パス名の配列から画像へのパスを取得して各画像をロードし、メソッドimageWithContentsOfFileを使用して画像をロードすることをお勧めします。

私はこれを調べて、これを行う方法を探しましたが、運がありませんでした。誰かが私にこれを行う方法を教えてもらえますか?

4

1 に答える 1

2

あなたは以下のようにそれをするべきです、

if ([[filename pathExtension] isEqualToString:extension]) 
{
     [jpegFiles addObject:[UIImage imageWithContentsOfFile:[documentsDirectory stringByAppendingPathComponent:filename]]];
}
于 2012-03-17T10:05:02.107 に答える