NSMutableArray索引混合起来

我目前正在尝试iCarousel Multiple Carousel例子。 在我的数组中,我用NSMutableDictionary添加图像:

我有两个这样的:(myImages和myImages2我的两个插槽加载在ViewDidLoad旋转木马)

 self.myImages = [NSMutableArray array]; for(int i = 0; i <= 10; i++) { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDir = [paths objectAtIndex:0]; NSString *savedPath = [documentsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"myImages%d.png", i]]; if([[NSFileManager defaultManager] fileExistsAtPath:savedPath]){ NSMutableDictionary *container = [[NSMutableDictionary alloc] init]; [container setObject:[UIImage imageWithContentsOfFile:savedPath] forKey:@"image"]; [container setObject:[NSNumber numberWithInt:i] forKey:@"index"]; [images addObject:container]; [container release]; // if not using ARC } } 

在我的iCarousel:

 - (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view { if (carousel == carousel1) { NSDictionary *obj = [items1 objectAtIndex:index]; view = [[UIImageView alloc] initWithImage:[obj objectForKey:@"items1"]]; view.tag = index; }else { NSDictionary *obj = [items2 objectAtIndex:index]; view = [[UIImageView alloc] initWithImage:[obj objectForKey:@"items2"]]; view.tag = index; } return view; } 

在另一个视图中,这些数组也被加载,用户有机会select一个图像进行比较,

当用户select一个图像时,与其标签相当的int就会传递到我的两个Carousel所在的位置。

这是我如何比较他们:

 NSInteger image = [prefs integerForKey:@"image"]; NSInteger image1 = [prefs integerForKey:@"image2"]; if (image == [(UIImageView*)[self.carousel1 currentItemView] tag] || image2= [(UIImageView*)[self.carousel2 currentItemView] tag] || ) { 

我这样删除一个索引:

  NSInteger index = carousel1.currentItemIndex; [carousel1 removeItemAtIndex:index animated:YES]; [items1 removeObjectAtIndex:index]; 

我想我是错误地删除它,因为索引没有更新,我想要的是保持其索引不调整像这样的图像在这里:

在NSMutableArray中删除

如果我明白你现在要做的是什么,那就是把两个转盘移动到中间的那个转盘上,然后不要让索引简单地消失,那么你可以不去除数组中的项目,填充位置你正试图删除一个无图像(或有你select的支持有效的图像),并标记说明它已经匹配。

这当然取决于我对你想要的东西的理解是否有效。