ashfurrow / ARCollectionViewMasonryLayout

MIT License
185 stars 16 forks source link

Layout is asking for ARCollectionElementKindSectionStickyHeader?? #36

Open glm4 opened 7 years ago

glm4 commented 7 years ago

Why the layout is asking for a reusable view for kind ARCollectionElementKindSectionStickyHeader if I never registered it to my collection or implemented the - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForStickyHeaderInSection:(NSInteger)section; method?

ashfurrow commented 7 years ago

Hmm, it shouldn't be doing that. Can you provide some of the setup code, or a sample project that demonstrates the problem? More details about what's going on would definitely be helpful 👍

glm4 commented 7 years ago

Using 2.2.0 version of the library.

here is my configuration:

Setup:

if let layout = ARCollectionViewMasonryLayout(direction: .vertical) {
       let margin = collection.frame.width * 0.04
      layout.contentInset = UIEdgeInsets(top: 20, left: 0, bottom: 20, right: 0)
      layout.itemMargins = CGSize(width: margin, height: margin)
      layout.dimensionLength = collection.frame.width / 2 - (margin * 2)
      collection.collectionViewLayout = layout
    }

  let headerNib = UINib(nibName: HeaderReusableView.reuseIdentifier, bundle: nil)
    collection.register(headerNib, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: HeaderReusableView.reuseIdentifier)

Then delegate methods:

func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
      guard let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: HeaderReusableView.reuseIdentifier, for: indexPath) as? HeaderReusableView else {
        return HeaderReusableView()
      }
      return header
  }

  func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
    return CGSize(width: collectionView.frame.width, height: collectionView.frame.height * 0.15)
  }

If I leave it like that it crashed and it said that the view obtained for ARCollectionElementKindSectionStickyHeader was not obtained calling dequeue... .

I had to add:

collection.register(headerNib, forSupplementaryViewOfKind: ARCollectionElementKindSectionStickyHeader, withReuseIdentifier: HeaderReusableView.reuseIdentifier) to make it work but I think this shouldn't be needed right?

ashfurrow commented 7 years ago

Right, so when you return HeaderReusableView(), what needs to happen instead is to call this function which will create one for you. Try it out and let me know how it goes.

glm4 commented 7 years ago

But that function needs a reuse identifier previously registered, which is what I don't want to do(Or should I even its not in the documentation).

ashfurrow commented 7 years ago

Sorry, I guess I'm confused. Can you describe the initial problem again?

glm4 commented 7 years ago

The collectionView is calling the func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView delegate method. Which I think it is not good, since I never registered that kind or implemented the referenceSizeForStickyHeaderInSection method of the layout.

ashfurrow commented 7 years ago

Okay, thanks. I'm not sure what's going on. Have you implemented the standard, non-sticky header delegate function? There are two (source code).

To help me track down the problem and provide a solution, could you please create a sample project demonstrating the problem? Please provide as much detail as possible (what you expect, what happens instead, that kind of stuff).

glm4 commented 7 years ago

Yes, I implemented the standard(collectionView:self.collectionView layout:self referenceSizeForHeaderInSection:indexPath.section) header(the one I need, I dont want the sticky ). I'll get back to you as soon as I can create the demo project. Thanks a lot.

ashfurrow commented 7 years ago

Okay, thanks!