首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iCarousel问题

iCarousel问题
EN

Stack Overflow用户
提问于 2013-02-05 15:17:31
回答 1查看 1.2K关注 0票数 0

我试图用下面的代码将一个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]];

任何帮助都将是非常感谢的。

代码语言:javascript
复制
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];

代码语言:javascript
复制
- (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;

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-02-05 16:23:39

您正在实现一个-carousel:viewForItemAtIndex:方法,但是视图需要一个-carousel:viewForItemAtIndex:reusingView:方法。

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14710791

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档