2
votes

I've been working with a great bit of code LXReorderableCollectionViewFlowLayout (written by Stan Chang Khin Boon). It allows for moving items around in a UICollectionView

I have a collection view with multiple sections. The sections are using a header with several controls in them. I allow the user to create empty sections and drag items into these sections

I using the collection view to show multiple albums of photos. Each section correlates to a different album. Dragging a photo from "Album 1" to "Album 2" works fine when each album already has items in it.

But, if the album (section) is empty, I can't move objects into that empty section.

I think the problem is with "indexPathForItemAtPoint". This method provides the correct NSIndexPath if the section has items in it. But if it's empty, it always returns section = 0, row = 0.

When I cross the border from section "0" into section "1" the NSIndexPath theIndexPathOfSelectedItem goes to 0,0 (section, row). I would have expected it to go to 1,0.

The problem seems to be with "indexPathForItemAtPoint". It isn't taking into consideration that the section might be empty and just defaults to 0, 0 when I cross the border into a different (and empty) section.

Like I said earlier, if there are items already in section "1" then the indexPath is set correctly.

Any ideas on what I'm doing wrong?

1

1 Answers

2
votes

I ended up placing a dummy (but invisible) item in the empty section. When I create a new section, I place a dummy value in the section. I make it invisible so that it doesn't show. Anytime I add a new item OR remove an item from a section I test to make sure that the dummy item is there.

IMPORTANT: If there is at least 1 real item in the section, I remove the dummy value. Otherwise, the collection list tries to draw it.

I'm sure there is a better way of doing this. If you know how, please post a new answer.

Hope this helps.