我正在从两个可变数组创建一个数组。 数组 1 有 3 个对象,数组 2 也有 3 个对象 我收到一条崩溃消息,提示“无法识别的选择器已发送到实例”,为什么这不起作用?
初始化两个数组:
self.array1 =[[NSMutableArray alloc]initWithObjects:@"word", @"word2", nil];
self.array2 =[[NSMutableArray alloc]initWithObjects:@"this goes with word1", @"this goes with the second word", nil];
NSMutableArray *objects;
for (int i=0 ; i<[array1 count]; i++){
for (int j=0 ; j<[array2 count]; j++){
objects = [[NSMutableArray alloc]init];
objects=[array1 objectAtIndex:i][[array2 objectAtIndex:j]];
}
}
最佳答案
如果我对你的理解正确,你需要使用字典来提供你想要的那种查找机制:
self.array1 = @[@"word", @"word2"].mutableCopy;
self.array2 = @[@"this goes with word1", @"this goes with the second word"].mutableCopy;
NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:self.array2
forKeys:self.array1];
NSLog(@"%@", dictionary[@"word"]);
// Prints "this goes with word1".
关于ios - 二维数组 Objective-C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22877826/