从图像中的文件夹装阵 - X code [英] Loading array from folder of images - xcode

查看:88
本文介绍了从图像中的文件夹装阵 - X code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些麻烦加载从文件中的图像到一个数组。我用我已经在这里找到问题相结合,与我的想法....我是新来的Objective-C和生锈的其余部分。

I am having some trouble loading images from a file into an array. I have used a combination of questions I have found on here, and am out of ideas.... I am new to objective-c and rusty on the rest.

我的viewDidLoad中简单地调用我的showPics方法和测试的缘故,我有_imgView只显示图像在数组中的位置1。

My viewDidLoad simply calls my showPics method, and for testing sake I have the _imgView just show the image at position 1 in the array.

这很可能是与我展示以及影像的方式有问题。在我的故事板:(imgView标题)

It could very well be a problem with the way I am showing the images as well. I have a ViewController and one ImageView (titled: imgView) in my Storyboard.

这是我的showPics方式:

here is my showPics method:

-(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中:

Here is my viewDidLoad:

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

下面是我的ViewController.h

Here is my ViewController.h

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

@end

请让我知道如果你需要什么,并预先感谢您!

Please let me know if you need anything else and thank you in advance!

推荐答案

在你的 showPics 方法,比最初的for循环等,所有引用了 PhotoArray 而应该是 imgQueue 引用。 PhotoArray 是路径名的列表。 imgQueue 是实际的UIImage 对象的数组。

In your showPics method, other than the initial 'for-loop', all of your references to PhotoArray should instead be references to imgQueue. PhotoArray is a list of pathnames. imgQueue is the array of actual UIImage objects.

-(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];
    }
}

这篇关于从图像中的文件夹装阵 - X code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆