在我的应用程序中,我使用 for 循环在 NSMutableArray 中添加数据。所有都正确添加,但问题是如果迭代次数增加,数据在特定索引值处变为零。我的代码如下所示:
NSArray * sortedArray =[FilterProjectsArray sortedArrayUsingDescriptors:descriptors];
NSMutableArray *Array1=[[NSMutableArray alloc]initWithArray:sortedArray];
[appdelegate.filtersArray addObject:[Array1 mutableCopy]] ;
for (int i=0; i<[appdelegate.filtersArray count]; i++)
{
NSLog(@"object in filtersarray count is %d",[[appdelegate.filtersArray objectAtIndex:i]count]);
}
为此,我在控制台中得到如下输出:
object in filtersarray count is 9
object in filtersarray count is 9
object in filtersarray count is 2
object in filtersarray count is 0
object in filtersarray count is 2
object in filtersarray count is 9
object in filtersarray count is 0
object in filtersarray count is 0
object in filtersarray count is 9
object in filtersarray count is 2
object in filtersarray count is 0
object in filtersarray count is 0
object in filtersarray count is 0
object in filtersarray count is 2
object in filtersarray count is 3
object in filtersarray count is 0
object in filtersarray count is 0
object in filtersarray count is 0
object in filtersarray count is 0
object in filtersarray count is 3
这就是我得到的输出,我不知道它为什么会这样。因此,如果有人对此有任何想法,请告诉我。