1
votes

I've been messing around with iCarousel (linky: https://github.com/nicklockwood/iCarousel) for a while now and there's one thing I can't get my head around.

It's loading 2 or more nibs into the one carousel. This is the current code to load the same nib for all the items in the carousel:

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
if (!view)
{
    //load new item view instance from nib
    //control events are bound to view controller in nib file
    view = [[[NSBundle mainBundle] loadNibNamed:@"ItemView" owner:self options:nil] lastObject];

       }
return view;
}

It's the standard code from the ControlsDemo in iCarousel.

Am I right in saying that a simple If statement can be applied to the code above to populate the carousel with a different nib for each item?

Or will I have to go down the route of loading an array of nib files at the start and just reference them in the method above?

Or is there a completely different way to do this?

1

1 Answers

0
votes

The issue was incredibly simple, i was over complicating it big time.

Here's the code that I added to the above sample to fix it:

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
    if (index == 0) {
        view = [[[NSBundle mainBundle] loadNibNamed:@"nib1" owner:self options:nil] lastObject];
    } else {
        view = [[[NSBundle mainBundle] loadNibNamed:@"nib2" owner:self options:nil] lastObject];
    }
    return view;
}