So I want to highlight a specific UIView
in iCarousel when I click a button within that view and I want to be able to highlight as many views as I want within the carousel. So I have a button that sets the alpha of a UIImageview
within the view the problem that I'm running into is although it knows the index of the view I don't know how to call the corresponding index of the UIImageview
within that view. So I setup the UIImageview
within a custom nib and I have this code setting up the iCarousel's view it:
UPDATED based on @danh answer
//.h
@property (nonatomic, strong)NSMutableSet *selected;
//.m
- (void)viewDidLoad
{
self.selected = [NSMutableSet set];
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
//create new view if no view is available for recycling
if (view == nil)
{
view = [[[NSBundle mainBundle] loadNibNamed:@"ItemView" owner:self options:nil] lastObject];
}
int chkTag = checkImg.tag;
checkImg = (UIImageView *)[checkImg viewWithTag:chkTag];
NSNumber *indexNum = [NSNumber numberWithInt:index];
// here's where the view state gets set
checkImg.alpha = ([self.selected member:indexNum])? 1.0 : 0.0;
return view;
}
Then I have this called when the specific view is being selected:
- (void)carouselCurrentItemIndexUpdated:(iCarousel *)carousel1{
NSInteger indexInt = carousel1.currentItemIndex;
NSNumber *index = [NSNumber numberWithInt:indexInt];
if ([self.selected member:index]) {
[self.selected removeObject:index];
} else {
[self.selected addObject:index];
}
// now just reload that item, and let the viewForItemAtIndex
// take care of the selection state
[carousel reloadItemAtIndex:indexInt animated:NO];
}
Which works but only allows me to select one item at a time and check it. I want to be able to select/unselect multiple items at a time.