首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iCarousel重复图像

iCarousel重复图像
EN

Stack Overflow用户
提问于 2013-09-30 16:34:54
回答 1查看 735关注 0票数 1

我在我的应用程序中使用了惊人的iCarousel库。但我正面临着一个问题。我使用此代码将数据填充到旋转木马中。

代码语言:javascript
复制
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
   //return the total number of items in the carousel
   return [items count];
}

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
    UILabel *label = nil;
UIImageView *imageView = nil;

    //create new view if no view is available for recycling
if (view == nil)
{
    view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width - 60, [[UIScreen mainScreen] bounds].size.height -150)];
    view.contentMode = UIViewContentModeCenter;
    CGFloat width = [[UIScreen mainScreen] bounds].size.width;
    CGRect webFrame = CGRectMake(0.0, 0.0, width - 60, width - 60);
    imageView = [[ UIImageView alloc ] initWithFrame:webFrame];
    [view addSubview:imageView];
    label = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 240.0, width -60, 260.0)];
    label.backgroundColor = [UIColor clearColor];
    label.textAlignment = NSTextAlignmentCenter;
    label.font = [label.font fontWithSize:22];
    label.numberOfLines = 5;
    label.lineBreakMode = NSLineBreakByWordWrapping;
    label.tag = 1;
    [view addSubview:label];
}
else
{
    //get a reference to the label in the recycled view
    label = (UILabel *)[view viewWithTag:1];
}

NSString *imageName = [NSString stringWithFormat:@"%@.pdf",[[items objectAtIndex:index] objectAtIndex:0]];
NSLog(@"Image File Name: %@", imageName);
NSLog(@"Image Explanation: %@", [[items objectAtIndex:index] objectAtIndex:1]);
[imageView setImage:[ UIImage imageWithPDFNamed:imageName atSize:CGSizeMake( 150, 130 ) ]];
label.text = [[items objectAtIndex:index] objectAtIndex:1];

return view;
}

numberOfItemsInCarousel返回38,但旋转木马只显示6幅图像,然后循环地重复它们。Lable文本根据数组索引正确显示。我怎么才能修好它?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-09-30 17:00:30

您不能从重用的视图中获取imageView,请阅读下面一行

代码语言:javascript
复制
[imageView setImage:[ UIImage imageWithPDFNamed:imageName atSize:CGSizeMake( 150, 130 ) ]];

作为

代码语言:javascript
复制
[nil setImage:[ UIImage imageWithPDFNamed:imageName atSize:CGSizeMake( 150, 130 ) ]];

view != nil。获取imageView的方式与您为label所做的一样。

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

https://stackoverflow.com/questions/19099322

复制
相关文章

相似问题

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