iCarousel问题

时间:2013-02-05 15:17:31

标签: ios icarousel

我正在尝试使用下面的代码将iCarousel添加到现有项目中,但我收到此错误:MemberCatalog[14990:1a903] -[MainViewController carousel:viewForItemAtIndex:reusingView:]: unrecognized selector sent to instance 0xa0589b0.

iCarousel.m中抛出错误的行是:view = [_dataSource carousel:self viewForItemAtIndex:index reusingView:[self dequeueItemView]];

任何帮助都会非常感激。

carouselItems = [NSArray arrayWithObjects:
         [UIImage imageNamed:@"iLibrary+Featured_AM-RAH.png"],
         [UIImage imageNamed:@"iLibrary+Featured_CCA.png"],
         [UIImage imageNamed:@"iLibrary+Featured_GI-PA.png"],
         nil];

// Initialize and configure the carousel
    carousel = [[iCarousel alloc] initWithFrame:self.view.bounds];
    carousel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    carousel.type = iCarouselTypeCoverFlow2;
carousel.delegate = self;
carousel.dataSource = self;

    [self.view addSubview:carousel];

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index
{
    UIImage *image = [carouselItems objectAtIndex:index];
    UIButton *button = [[[UIButton alloc] initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)] autorelease];
    [button setBackgroundImage:image forState:UIControlStateNormal];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    button.titleLabel.font = [button.titleLabel.font fontWithSize:50];
    button.tag=index;
    return button;

}

1 个答案:

答案 0 :(得分:2)

您正在实施-carousel:viewForItemAtIndex:方法,但视图需要-carousel:viewForItemAtIndex:reusingView:方法。

您需要使用reusingView:(UIView *)view参数更新您的方法,你会没事的。您还应该使用该可重用视图,而不是分配越来越多的视图,但这是另一个故事。