Reputation: 27295
I have a UICollectionView. Each cell contains a UITextField. I want a callback when display is complete, so I can query a model object for which textField should be the firstResponder, then make it the firstResponder. Can I get that callback? Or is there another natural way to accomplish this?
Upvotes: 7
Views: 10059
Reputation: 385840
If you send the layoutIfNeeded
message to your collection view, it will update its children (adding and deleting cells as necessary) before returning. Thus you can make it update synchronously, then perform your post-reload actions.
[myCollectionView layoutIfNeeded];
[self chooseFirstResponderFromCells:myCollectionView.visibleCells];
Upvotes: 11
Reputation: 3541
Never tried it but you might do it by putting code in
dequeueReusableCellWithReuseIdentifier:forIndexPath:
to get the count of visible cells (maybe [visibleCells count]) then tracking how many have actually been processed, then making your callback after all have been displayed. You'd have to reset the count between scrolls though.
Not clean, but should work. I don't know of any way to get a callback short of that.
Upvotes: 0
Reputation: 2552
As far as an actual callback method, I don't think there is one for collection view loading. The only one I know is performBatchUpdates:completion
, and that's pretty unrelated. In my experience, though, collection views are loaded and ready to go by the time viewDidAppear
is called, so I would set the first responder there.
Hope this helps!
Upvotes: 5