1

でヘッダーの動作を模倣するためにUICollectionView使用しています。ヘッダーの内部には、 上の制御データがあります。だから私が欲しいのは、セグメントをタップして(APIを呼び出して)データをリロードして実行することですが、常にCSStickyHeaderFlowLayoutUITableViewSegmentedControlUICollectionViewreloadData

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

何かアドバイス?:)

4

1 に答える 1

0

あなたの間違いは、選択が失われる可能性があるビューレイヤー内にのみ選択を保存することです。ユーザーが別のセグメントを選択したときに、新しい選択インデックスを使用してプロパティを設定する必要があります。次に、データをリロードすることで、この変更されたプロパティに対応できます。ヘッダー ビューに戻る前に、選択したセグメントを以前に保存したインデックスに設定します。そうすれば、選択が失われることはありません。

これに加えて、 reloadData を避け、代わりに実際に変更されたアイテムのみをリロードする必要があります。

于 2015-05-12T06:40:13.650 に答える