Adding a header to HitsCollectionWidget

Hi,
Can you point me to any documentation that describes how to add a header to the HitsCollectionWidget for iOS?

Usually, the delegate for UICollectionViewDataSource would implement the method collectionView(collectionView: viewForSupplementaryElementOfKind:IndexPath) that would return the UICollectionReusableView.

Looking at the definition for HitsCollectionViewDataSource, there is no method that I can see which allows the header to be customised in the implementing View Controller.

Thanks
Alex

Hey @amundy74,

There are 2 ways you can have more flexibility for your HitsCollectionWidget:

  • ViewController Inheritance (read about it here)
  • HitsViewModel (see an example here)

I hope that helps!

Cheers!
Guy

Hi Guy,

Thanks for the tips. The ViewController Inheritance approach was what I needed.

Many thanks
Alex

Hi Guy,

As mentioned, I managed to get access to the other collectionDataSource methods from following the ViewController inheritance approach, which enabled me to add a header view into the collection view.

However, I have a subview in the UICollectionReusable view that I wish to be updated with search results.

I was expecting to be able to make my controller conform to ResultingDelegate, so that I could populate a data source that would be used by the UICollectionReusable subview. Unfortunately, I must be doing something wrong as the delegate method on(results:error:userInfo) doesn’t get called.

So, if I have a ViewController that is a subclass of HitsCollectionViewContoller, how can I access the ResultingDelegate method, so my hits can be used by another view?

Thanks
Alex

Hello again!

Sorry for the late reply. Can you copy paste for me the part where you’re trying to make your UICollectionReusable view listen to results?

By the way, if you want an example of a custom view that conforms to ResultingDelegate, take a look at our example repo, the Icebnb example, specifically this widget. Let me know if this is helpful!

Hi Guy,

Thanks for coming back to me. I overcame my issue.

Regards
Alex

1 Like