NSMutablearrays的难度

初学iOS的开发者在这里。 我的数组中有一个问题。 我正在用iCarousel做一个应用程序。 每当它停止到一个视图,它将删除当前视图或索引,如下所示:

NSInteger index = carousel.currentItemIndex; [carousel removeItemAtIndex:index animated:YES]; [images removeObjectAtIndex:index]; 

所以我的数组有这样的索引:

0 1 2 3 4 5

当我使用上面的方法(例如它在视图3上)它变成这样:

0 1 2 4 5

如何保持相同的数组索引/值,即使我删除? 还是应该更新?

我尝试使用[carousel reloadData]; 但仍然没有效果。

使用[carousel replaceItemAtIndex:index withObject:[NSNull null]]; 并检查对象是否为NSNulltypes,然后不做任何事情或根据您的要求。

1)在实现中你需要一个@synthesize调用。 码:

 @synthesize myNSMutableArray; 

2)使用“自我”。 使用由参数产生的setter / getters。 码:

 self.myNSMutableArray = [[NSMutableArray alloc] initWithObjects:@"object1.png", @"object2.png", @"object3.png", nil]; [self.myNSMutableArray replaceObjectAtIndex:0 withObject: @"newObject.png"]; Without the "self." you are changing the iVar directly.