iphone - iCarousel 重复图片

标签 iphone ios objective-c xcode5 icarousel

我在我的应用程序中使用了很棒的 iCarousel 库。但我面临一个问题。我正在使用此代码将数据填充到轮播中。

- (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 张图像,然后循环重复。标签文本根据数组索引正确显示。 我该如何解决?

最佳答案

您没有从重复使用的 View 中获取 imageView,请阅读该行

[imageView setImage:[ UIImage imageWithPDFNamed:imageName atSize:CGSizeMake( 150, 130 ) ]];

作为

[nil setImage:[ UIImage imageWithPDFNamed:imageName atSize:CGSizeMake( 150, 130 ) ]];

view != nil 时。获取 imageView 的方式与获取 label 的方式相同。

关于iphone - iCarousel 重复图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19099322/

相关文章:

ios - 将 NSString 转换为字节

iphone - 我最近发布的应用程序更新在 info.plist 文件中没有最新/正确的值

ios - 有什么方法可以检查应用程序是否已安装或更新?

ios - UITableView 拖放功能

ios - 如何在 XCode 4.2.1 (SDK5.0) 中安装旧版 iOS 模拟器

objective-c - 制作一个复选框来打开和关闭 Dock 图标

iphone - 使用 Nuance SDK : Generate . wav 文件在 iPhone 中进行文本到语音转换

ios - OSXs "texturetool"有哪些替代方案可以将 png 图像数据转换为 PowerVR

iphone - iOS CoreLocation 高度

iphone - 河豚 objective-c 实现