如何将 NSMutableArray 添加为 NSMutableArray 的 objectAtIndex [英] How to add NSMutableArray as objectAtIndex for NSMutableArray
本文介绍了如何将 NSMutableArray 添加为 NSMutableArray 的 objectAtIndex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将 NSMutableArray
添加为另一个 NSMutableArray
How to add NSMutableArray
as an object(i) for another NSMutableArray
我的代码是:
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) 的对象..
Here i need to add tempImages as object of (i) for yearImages..
我需要如下结果:
[yearImages objectAtIndex:i];// result need as arrayobjects here
推荐答案
在添加 tempImages 后,您将其从 tempImages 中删除,因此结果将是一个空数组数组.您应该添加 tempImages 的副本:
[yearImages addObject:tempImages.copy]
(或 mutableCopy,如果您需要)You are removing the objects from tempImages after you add it, so the result will be an array of empty arrays. You should add a copy of tempImages instead:
[yearImages addObject:tempImages.copy]
(or a mutableCopy if you require that)这篇关于如何将 NSMutableArray 添加为 NSMutableArray 的 objectAtIndex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文