我目前正在尝试这个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;
}
在另一个视图中,这些数组也被加载,用户有机会选择一个图像进行比较,
当用户选择一个图像时,一个与其标签等效的 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];
我想我把它删错了,因为索引没有更新,我想要的是保持它的索引不要像这里的图像一样调整: