I'm currently trying the iCarousel
Multiple Carousel
example.
Here in my array, I've add images with NSMutableDictionary:
I have two of these: ( myImages and myImages2 for my two slot in carousel loaded in 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
}
}
in my 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;
}
In another View, these arrays are also loaded, the user has a chance to pick an image to compare to with,
when an user pick an image an int equivalent to its tag is pass to where my two Carousel is.
Here is how I compare them:
NSInteger image = [prefs integerForKey:@"image"];
NSInteger image1 = [prefs integerForKey:@"image2"];
if (image == [(UIImageView*)[self.carousel1 currentItemView] tag] || image2= [(UIImageView*)[self.carousel2 currentItemView] tag] || ) {
I delete an index this way:
NSInteger index = carousel1.currentItemIndex;
[carousel1 removeItemAtIndex:index animated:YES];
[items1 removeObjectAtIndex:index];
I think I'm deleting it the wrong away, because the index arent updated, what i wanted is to maintain its index not adjust like this images right here:
Deleting in NSMutableArray