iCarousel - viewForItemAtIndex在启动时加载所有索引

时间:2014-07-16 03:52:28

标签: ios objective-c icarousel

我正在使用iCarousel来显示信息。每个索引(共7个)都有一个唯一的图像,上面有标签。每个都设置了if语句if (index == 0){...}等。

然而,当我加载页面(和轮播)时,最初只加载前三个图像。系统使用延迟加载等待旋转木马转向抓取下一个图像。我可以通过print语句证明索引实际上从2增加到6 [0..6]。但出于某种原因,我的旋转木马图像在第三个之后重复。

示例:星期一,星期二,星期三,星期一,星期二,星期三,星期一 应该是:周一,周二,周三,周四,周五,周六,周日

任何想法如何解决这个问题?

更多测试 对于索引0-2,视图为零,但对于索引3+,视图不是nil而if跳过。知道怎么解决这个问题吗?

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view{

UILabel *label = nil;
NSLog(@"INDEX is %i", index);
//create new view if no view is available for recycling
if (view == nil)
{
    view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200.0, 200.0)];
    //view = [[UIImageView alloc] init];
    ((UIImageView *)view).image = [UIImage imageNamed:_locationDetailModel[2]];
    view.contentMode = UIViewContentModeCenter;
    label = [[UILabel alloc] initWithFrame:view.bounds];
    label.minimumScaleFactor = 8./label.font.pointSize;
    label.adjustsFontSizeToFitWidth = YES;
    [label setFont:[UIFont boldSystemFontOfSize:12]];
    ...
    if (index == 0){
        label.backgroundColor = [UIColor colorWithPatternImage:[self resizeForCarousel:[UIImage imageNamed:@"Monday_Hours.jpg"]]];
        }
    } else if (index == 1) {
        label.backgroundColor = [UIColor colorWithPatternImage:[self resizeForCarousel:[UIImage imageNamed:@"Tuesday_Hours.jpg"]]];
    } else if (index == 2){
        label.backgroundColor = [UIColor colorWithPatternImage:[self resizeForCarousel:[UIImage imageNamed:@"Wednesday_Hours.jpg"]]];
    } else if (index == 3){
        label.backgroundColor = [UIColor colorWithPatternImage:[self resizeForCarousel:[UIImage imageNamed:@"Thursday_Hours.jpg"]]];
    } else if (index == 4){
        label.backgroundColor = [UIColor colorWithPatternImage:[self resizeForCarousel:[UIImage imageNamed:@"Friday_Hours.jpg"]]];
    } else if (index == 5){
        label.backgroundColor = [UIColor colorWithPatternImage:[self resizeForCarousel:[UIImage imageNamed:@"Saturday_Hours.jpg"]]];
    } else if (index == 6){
        label.backgroundColor = [UIColor colorWithPatternImage:[self resizeForCarousel:[UIImage imageNamed:@"Sunday_Hours.jpg"]]];
    }
    label.textAlignment = NSTextAlignmentCenter;
    //label.textAlignment = UITextAlignmentCenter;
    label.font = [label.font fontWithSize:50];
    label.tag = 1;
    [view addSubview:label];
}
else
{
    label = (UILabel *)[view viewWithTag:1];
}
return view;

}

1 个答案:

答案 0 :(得分:1)

关键是要删除if(view == nil)

前3个索引点有效,但之后它们被启动,不再是