iCarousel currentItemIndex 没有改变

iCarousel currentItemIndex doesn't change

所以我使用 iCarousel 在我的应用程序中显示一些图像,我需要一个标签来在我滚动时显示当前图像索引(例如“3/10”)。这是我的代码:

- (void)carouselCurrentItemIndexDidChange:(iCarousel *)carousel
{
    NSLog(@"index: %i", currentItemIndex);

    imageNumber.text = @"";        
    imageNumber.text = [[[imageNumber.text
                      stringByAppendingString:[NSString stringWithFormat:@"%i", currentItemIndex+1]]
                     stringByAppendingString:@"/" ]
                    stringByAppendingString:[NSString stringWithFormat:@"%i", carousel.numberOfItems]];    
}

尽管每当我滚动时都会调用此方法,但 currentItemIndex 永远不会改变。它保持为 0。 有谁知道这是为什么,或者可以建议我在用户滚动轮播时更新索引的另一种方法?

首先,您需要

    carousel.currentItemIndex

而不是 currentItemIndex

其次,您还可以实现 carouselDidEndScrollingAnimation: 委托并检查索引:

- (void)carouselDidEndScrollingAnimation:(iCarousel *)carousel
{
    NSLog(@"index: %i", carousel.currentItemIndex);
}