Can we add a UISearchBar to the UICollectionView header

I use UICollectionView, and I want to add to it UISearchBaror UISearchDisplayController. I can do it. I want, please, an example.

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    UICollectionReusableView *reusableview = nil;

    if (kind == UICollectionElementKindSectionHeader) {

        CollectionReusable *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeadCell" forIndexPath:indexPath];

        reusableview = headerView;
    }

    if (kind == UICollectionElementKindSectionFooter) {

        CollectionReusable *footerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"FootCell" forIndexPath:indexPath];

        reusableview = footerView;
    }

    return reusableview;
}
+4
source share
1 answer

A bit late, but this repository contains a large piece of code dedicated to this problem.

-1
source

Source: https://habr.com/ru/post/1526527/


All Articles