我正在尝试iCarousel
Multiple Carousel
示例。 在这里,在我的数组,我和的NSMutableDictionary添加图像:NSMutableArray索引混合起来
我有两个:(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;
}
在另一视图中,这些阵列也被加载,则用户有机会选择一个图像进行比较,以与,
当用户选择一个与它的标签等价的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];
我想我删除它错了,因为该指数的arent更新,是什么我想保持其索引不调整像这样的图像在这里:
看着这篇文章和你的其他文章,我看不到问题。在标准动态数组中,当一个项目被删除时,所有其他项目的索引都会被更新。在这种情况下,你永远不应该有这样一种情况,即你从列表0,1,2,3中删除了项目1,并以0,2,3结束。正确的结果数组是0,1,2! – trumpetlicks
但我真的有问题比较采摘imageView(标签视图)与我的carouselVIew,所以我认为我的数组有问题,我真的不知道如何解决它。 – Bazinga
这真的是你的代码,因为你有一个额外的|| (或)在您的比较结尾处if如果 – trumpetlicks