0

I am new to objective C

I want to add in a NSMutableArray on each line 2 values ( i i , i j, i n)

I have this code:

UPDATE:
I've decided to create 2 NSMutableArrays:

NSMutableArray *sections = [[NSMutableArray alloc] init];
NSMutableArray *second_array = [[NSMutableArray alloc] init];
@try {
        for (Table *table in Class_1]) 
        {
            NSMutableArray *second = [[NSMutableArray alloc]init];

            for (id item in table.NSSET_DATAS)
            {
                [second addObject id];
            }
            [sections addObject:table.firstVal];
            [second_array addObject:second];

            // how to add the NSArray second?

        }
    }
@catch (NSException *exception) {
        NSLog(@"ERROR IN SETLISTCONTENT");
    }

How to retrieve from position 5 both values from position 1 and the array? I have error when doing this:

NSString value= [self.second_array  objectAtIndex:0]objectAtIndex:0];
4

2 回答 2

1

将这两个值存储在 NSMutableDictionary 中,将 Dictionary 添加到 NSMutableArray 中。您将在每个索引中获得两个值。像这样的示例。

NSMutableArray *array = [[NSMutableArray allao]init];

NSMutableDictionary *data = [[NSMutableDictionary alloc]init];
[data setObject:first forKey:@"first"];
[data setObject:second forKey:@"second"];

//Add this to your array
[array addObject:data];

我希望它对你有帮助...

于 2013-10-24T10:00:07.737 回答
0

First thing you cannot add object in NSArray, if you want to add then take NSMutableArray. Second thing if you want to add in mutablearray then use below api:-

[second addObjectsFromArray:sections];

here it is wrong, As in your one mutablearray you have one object which is also an mutablearray and then inside you have string. So extract like that below:-

NSString value= [self.second_array  objectAtIndex:0]objectAtIndex:0];

NSArray *newArray=[self.second_array objectAtIndex:0];
NSString *value=[newArray objectAtIndex:0];
NSLog(@"%@",value);
于 2013-10-24T09:18:33.073 回答