2017-05-05 67 views
0

我有一個UIViewControllerUICollectionView附加上。問題是每當我向上滾動集合視圖時都會調用viewForSupplementaryElementOfKind。有什麼方法可以多次停止呼叫viewForSupplementaryElementOfKindUICollectionView viewForSupplementaryElementOfKind多次調用

+0

它是根據你的部分稱爲數 –

+0

是否有任何解決方案停止調用一個以上的時間? –

+0

哈哈哈,然後做喜歡,設置一個部分,並添加另一個東西是行 –

回答

0

viewForSupplementaryElementOfKind的調用取決於部分的數量和部分頁眉/頁腳的可用性。 viewForSupplementaryElementOfKind將被調用,每當具有頁眉或頁腳的部分顯示在視圖中

0

最後,我想出了一個解決方案,像一個魅力... 我設置標籤值爲每次我創建它並檢查標記值是否設置在viewForSupplementaryElementOfKind中時,每當我進入循環時。如果它被設置已經那麼它將不會再重新設計標籤

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath 
{ 
    if ([kind isEqualToString:UICollectionElementKindSectionHeader]) 
    { 
     UICollectionReusableView *reusableview = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView" forIndexPath:indexPath]; 
     if([reusableview viewWithTag:101] == nil) 
     { 
     [[reusableview viewWithTag:101] removeFromSuperview]; 
     pointsAmountLabel = [[UILabel alloc] init]; 
     pointsAmountLabel.frame = CGRectMake(0, 20, [UIScreen mainScreen].bounds.size.width, 20); 
     pointsAmountLabel.text = @"0"; 
     pointsAmountLabel.tag = 101; 
     pointsAmountLabel.font = [UIFont boldSystemFontOfSize:16]; 
     [reusableview addSubview:pointsAmountLabel]; 
    } 
    return reusableview; 
    } 
return nil; 
}