【问题标题】:iCarousel issueiCarousel 问题
【发布时间】:2013-02-05 15:17:31
【问题描述】:

我正在尝试使用以下代码将 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;

}

【问题讨论】:

  • 您是否正在实施-carousel:viewForItemAtIndex:reusingView:??
  • 是的。我做了:- (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]; [按钮 setBackgroundImage:image forState:UIControlStateNormal]; [按钮 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; button.titleLabel.font = [button.titleLabel.font fontWithSize:50]; button.tag=索引;返回按钮; }
  • 嗯,这个方法显然缺少reusingView: 部分
  • 谢谢你们,你们是最棒的。我正在实施 - (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index 而不是 - (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view跨度>
  • 我会发布一个答案,以便您关闭此问题。 ;)

标签: ios icarousel


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-20
    相关资源
    最近更新 更多