与NSMutableArray比较 [英] Comparing with NSMutableArray

查看:60
本文介绍了与NSMutableArray比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我从 NSDocumentDirectory 加载图像的 Array 1 中,我加载了图像并添加了 NSMutableDictionary :

In my Array 1, which I loaded images from NSDocumentDirectory, I loaded them and add a NSMutableDictionary:

self.images = [NSMutableArray array];
for(int i = 0; i <= 8; i++) 
{ 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDir = [paths objectAtIndex:0];

    NSString *savedImagePath = [documentsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"Images%d.png", i]]; 
    if([[NSFileManager defaultManager] fileExistsAtPath:savedImagePath]){ 
        NSMutableDictionary *container = [[NSMutableDictionary alloc] init];
        [container setObject:[UIImage imageWithContentsOfFile:savedImagePath] forKey:@"image"];
        [container setObject:[NSNumber numberWithInt:i] forKey:@"index"];
        [images addObject:container];
    } 
}   

在另一个数组 Array 2 中,我从应用程序中加载了它们.

In my other array Array 2, I loaded them from the app.

    self.images = [NSMutableArray arrayWithObjects:
                   @"01.jpg",@"02.jpg",@"03.jpg",@"04.jpg",@"05.jpg",@"06.jpg",@"07.jpg",nil];

我能够像这样将字符串添加到 Array 2 :

I was able to add string to Array 2 like this:

for (int x=1; x<8;x++) {
    // add as NSString
    [images addObject:[NSString stringWithFormat:@"%d", x]];

    }

并且能够像这样比较 Array 2 :

   NSInteger index = carousel.currentItemIndex;
    if ([[images objectAtIndex:index] intValue] == 1){

我想要做的是将其执行到 Array 1 .我知道 Array1 已经添加了 NSNumber ,但是我对 NSMutableDictionary 有点陌生,所以我不能与>数组2 .

What I wanted to do, is to do it to Array 1. I know Array 1 has been already added with NSNumber, but Im kinda new to NSMutableDictionary so I can't do it the same as Array 2.

可以和我的 Array 2 一样进行操作吗?

Can it be done the same as my Array 2 or what is the other way?

感谢您的帮助.

推荐答案

实际上,这里有字典数组,因为要添加的字典包含两个带有键 image 的对象.索引

Actually Here you have the array of dictionaries, because you are adding the dictionary which has two objects with keys image and index

因此,为了检索字典数组,

So, for retrieving the array of dictionaries,

只需记录一下,看看会发生什么

just log it and see what happens

编辑2.0

for(int i=0; i< [images count]; i++){
    NSNumber *num =[[images objectAtIndex:i] objectForKey:@"index"];

    int index = [num intValue];

    NSLog(@"%d",index)
}

这篇关于与NSMutableArray比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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