2014-07-16 26 views
2

我正在使用iCarousel來顯示信息。每個索引(總共7個)都有一個獨特的圖像,並且上面有標籤。每個設置if語句if (index == 0){...}iCarousel - viewForItemAtIndex在啓動時加載所有索引

但是,當我加載頁面(和傳送帶)只有前三個圖像加載最初。系統使用延遲加載來等待傳送帶轉向抓取下一個圖像。我可以通過打印語句證明索引確實增加了2,一直到6 [0..6]。但由於某種原因,我的傳送帶圖像在第三個之後重複。

舉例:週一,週二,週三,週一,週二,週三,週一 應該是:週一,週二,週三,週四,週五,週六,週日

任何想法如何解決這一問題?

更多的測試 索引0-2的觀點是零,但對指數3+的觀點是不是零和如果被跳過了。任何想法如何解決這個問題?

- (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; 

}

+0

解決:刪除了,如果(查看==無)。這是一個壞方法嗎? – Marcus

+1

添加此爲答案,接受並關閉該問題。 – rishi

回答

1

的關鍵是去除if(view == nil)

前3個指數點是有效的,但在這之後他們發起並不再爲零

+0

它可能會解決這個問題,但它不是一個好的選擇,因爲我們每次都在分配我們的UIImageView對象。 –

+0

@馬庫斯:它正在加載所有的圖像,但是,我們無法確定哪個項目在前面。 –