2014-09-26 147 views
5

我有我實現懶加載一個UICollectionView之前返回0,UICollectionView visibleCells滾動

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ 
     [self loadImagesToVisiableCells]; 
} 

它的工作原理好。但是,問題出現在任何滾動之前,第一個單元格顯示佔位符圖像。所以我嘗試調用我的檢索JSON文件顯示在下面的UICollectionView的回調loadImagesToVisiableCells,任何滾動前

- (void)handleReceivedData: (NSArray*)results returnArrayOrDic:(NSNumber *)returnArrayOrDic{ 
    NSLog(@"***************************"); 
    NSLog(@"handleReceivedData has been called from PromotionViewController"); 
    NSLog(@"jsonArray Length:%d",[results count]); 
    NSLog(@"jreturnArrayOrDic:%@",returnArrayOrDic); 
    if([returnArrayOrDic boolValue] == YES){ 
     for(NSDictionary *dealDic in results) { 
     NSLog(@"dealDic: %@", dealDic); 
     //to populate the dealArray 
     Deal *deal = [[Deal alloc] initWithDict:dealDic]; 
     [dealArray addObject:deal]; 
     } 
     NSLog(@"%d deals have been populated to dealArray",[dealArray count]); 
    }else{ 
     NSDictionary *jsonDictionary = (NSDictionary *)results; 
     for(id key in jsonDictionary) { 

     id value = [jsonDictionary objectForKey:key]; 

     NSString *keyAsString = (NSString *)key; 
     NSString *valueAsString = (NSString *)value; 

     NSLog(@"key: %@", keyAsString); 
     NSLog(@"value: %@", valueAsString); 
     } 
    } 
    [self.collectionView reloadData]; 
    [self loadImagesToVisiableCells]; 
} 

調試消息顯示,[的CollectionView visibleCells]計數]返回0

- (void)loadImagesToVisiableCells{ 
     NSLog(@"starting loadImagesToVisiableCells, visibleCells:%d",[[collectionView visibleCells] count]); 
.... 
} 

有什麼想法?

問候 錘

回答