我有一个UICollectionView
用来CSStickyHeaderFlowLayout
模仿UITableView
. 在标头内部有SegmentedControl
控制数据UICollectionView
。所以我想要的是在我点击段(调用 API)并执行时重新加载数据,reloadData
但它总是调用
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
那么什么是仅重新加载数据而不是标题的最佳方法,因为当reloadData
标题也会重新加载时,段将返回到第一个状态。
这是我的代码viewForSupplementaryElementOfKind
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
UICollectionReusableView *reusableView = nil;
if (kind == UICollectionElementKindSectionHeader) {
SegmentHeaderView *collectionHeader= [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"Header" forIndexPath:indexPath];
HMSegmentedControl *segmentedControl = [[HMSegmentedControl alloc] initWithSectionTitles:@[@"Popular", @"Lelang"]];
[segmentedControl setFrame:CGRectMake(0, 0, self.view.frame.size.width, 45)];
[segmentedControl addTarget:self action:@selector(segmentedControlChangedValue:) forControlEvents:UIControlEventValueChanged];
segmentedControl.backgroundColor = [NConfig FlatButtonGray];
segmentedControl.selectionIndicatorColor = [UIColor whiteColor];
segmentedControl.selectionIndicatorBoxOpacity=1;
segmentedControl.titleTextAttributes = @{NSForegroundColorAttributeName : [NConfig FlatButtonOrange]};
segmentedControl.selectedTitleTextAttributes = @{NSForegroundColorAttributeName : [NConfig FlatButtonOrange]};
segmentedControl.selectionStyle = HMSegmentedControlSelectionStyleBox;
segmentedControl.selectedSegmentIndex = HMSegmentedControlNoSegment;
segmentedControl.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationNone;
segmentedControl.shouldAnimateUserSelection = NO;
[segmentedControl setSelectedSegmentIndex:0 animated:YES];
[collectionHeader addSubview:segmentedControl];
reusableView = collectionHeader;
}
return reusableView;
}
有什么建议吗?:)