UICollectionView reloadData resigns first responder/dismisses keyboard when searchBar is in section header

前端 未结 2 1722
北荒
北荒 2020-12-09 09:51

I have a UICollectionView that have section header. In the section header I have a UISearchBar. I want to filter the content in my collection view

2条回答
  •  清歌不尽
    2020-12-09 10:29

    did you tried with one of this options?

    To reload just the new items

        [self.collectionView reloadItemsAtIndexPaths:indexPaths];
    

    To reload the complete section

        [self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];
    

    Or, if it doesn't work.. make searchBar first responder again after your updates

        [self.collectionViewPackages performBatchUpdates:^{
            [self.collectionView reloadData];
        } completion:^(BOOL finished) {
            [self.searchBar becomeFirstResponder];
        }];
    

提交回复
热议问题