2017-05-05 307 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; 
}