There is a method to get a cell by indexPath
(UICollectionView cellForItemAtIndexPath:
). But I can"t find a method to get one of the supplementary views like a header or footer, after it has been created. Any ideas?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
This method is often enough to serve the purpose of reloading on-screen supplementary views:
UPDATE
As of iOS 9, you can use
-[UICollectionView supplementaryViewForElementKind:atIndexPath:]
to get a supplementary view by index path.ORIGINAL
Your best bet is to make your own dictionary mapping index paths to supplementary views. In your
collectionView:viewForSupplementaryElementOfKind:atIndexPath:
method, put the view into the dictionary before returning it. In yourcollectionView:didEndDisplayingSupplementaryView:forElementOfKind:atIndexPath:
, remove the view from the dictionary.I would like to share my insight of the solution provided by rob mayoff but I can't post comment so I am putting it here:
For every one of you that tried to keep reference of the supplementary views being used by a collection view but who run into issues of loosing track too early because of
being called too many times, try using an NSMapTable instead of a dictionary.
I use
created like this:
so that when you are keeping a reference to a supplementary view:
it keeps only a WEAK reference to it in the NSMapTable and it keeps it AS LONG AS the object is not deallocated!
You don't need anymore to remove the view from
as the NSMapTable will lose the entry as soon as the view is deallocated.
First thing you have to do is check the box "Section Header" in the collection view's attribute inspector. Then add a collection reusable view just like you added your cell to the collection view, write an identifier and make a class for it if you need to. Then implement the method:
From there do exactly like you did with cellForItemAtIndexPath Its also important to specify if its a header or footer you are coding about:
use indexpath.section to know what section this is in also note that Header and EntrySelectionFooter are custom subclasses of UICollectionReusableView that I made