NSMutableArray难度

时间:2012-06-08 03:21:25

标签: iphone ios xcode

初学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];,但仍无效果。

2 个答案:

答案 0 :(得分:2)

使用[carousel replaceItemAtIndex:index withObject:[NSNull null]]; 并检查对象是否为NSNull类型,然后不执行任何操作或根据您的要求。

答案 1 :(得分:0)

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.