如何将NSMutableArray
添加为另一个NSMutableArray
的对象(i)
我的代码是:
yearImages = [[NSMutableArray alloc]init];
tempImages = [[NSMutableArray alloc]init];
for(int i =0; i< [yearImagesName count]; i++)
{
for(int j=0; j<[totalImagesName count]; j++)
{
if ([[totalImagesName objectAtIndex:j] rangeOfString:[yearImagesName objectAtIndex:i]].location != NSNotFound)
{
[tempImages addObject:[totalImagesName objectAtIndex:j]];
}
}
[yearImages addObject:tempImages];
[tempImages removeAllObjects];
}
NSLog(@"\n\n year%@",[yearImages objectAtIndex:0]); // getting null result
在这里,我需要为yearImages添加tempImages作为(i)的对象。
我需要如下结果:
[yearImages objectAtIndex:i];// result need as arrayobjects here
最佳答案
添加对象后,您将它们从tempImages中删除,因此结果将是一个空数组。您应该改为添加tempImages的副本:[yearImages addObject:tempImages.copy]
(或mutableCopy,如果您需要的话)
关于ios - 如何将NSMutableArray添加为NSMutableArray的objectAtIndex,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20262727/