2

ファイルから配列に画像をロードするのに問題があります。私はここで見つけた質問を組み合わせて使用​​しましたが、アイデアがありません。...私はobjective-cに不慣れで、残りはさびています。

私のviewDidLoadは単にshowPicsメソッドを呼び出します。テストのために、_imgViewは配列の位置1にある画像を表示するだけです。

画像の表示方法にも問題がある可能性があります。ストーリーボードにViewControllerと1つのImageView(タイトル:imgView)があります。

これが私のshowPicsメソッドです:

-(void)showPics
{
    NSArray *PhotoArray = [[NSBundle mainBundle] pathsForResourcesOfType:@"jpg" inDirectory:@"Otter_Images"];
    NSMutableArray *imgQueue = [[NSMutableArray alloc] initWithCapacity:PhotoArray.count];
    for (NSString* path in PhotoArray)
    {
        [imgQueue addObject:[UIImage imageWithContentsOfFile:path]];
    }
    UIImage *currentPic = _imgView.image;
    int i = -1;

    if (currentPic != nil && [PhotoArray containsObject:currentPic]) {
        i = [PhotoArray indexOfObject:currentPic];
    }

    i++;
    if(i < PhotoArray.count)
        _imgView.image= [PhotoArray objectAtIndex:1];

}

これが私のviewDidLoadです:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self showPics];
}

これが私のViewController.hです

@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIImageView *imgView;

@end

他にご不明な点がございましたら、お気軽にお問い合わせください。

4

1 に答える 1

3

あなたのshowPicsメソッドでは、最初の'for-loop'を除いて、へのすべての参照PhotoArrayは代わりにへの参照である必要がありますimgQueuePhotoArrayパス名のリストです。実際のオブジェクトimgQueueの配列です。UIImage

-(void)showPics {
    NSArray *PhotoArray = [[NSBundle mainBundle] pathsForResourcesOfType:@"jpg" inDirectory:@"Otter_Images"];
    NSMutableArray *imgQueue = [[NSMutableArray alloc] initWithCapacity:PhotoArray.count];
    for (NSString* path in PhotoArray) {
        [imgQueue addObject:[UIImage imageWithContentsOfFile:path]];
    }

    UIImage *currentPic = _imgView.image;
    int i = -1;

    if (currentPic != nil && [imgQueue containsObject:currentPic]) {
        i = [imgQueue indexOfObject:currentPic];
    }

    i++;
    if(i < imgQueue.count) {
        _imgView.image = [imgQueue objectAtIndex:1];
    }
}
于 2012-10-22T16:29:00.060 に答える