I'm trying to override UICollectionViewFlowLayout
, but I realized something strange. Here you can see a little code snippet:
#import <UIKit/UIKit.h>
@interface SimpleFlowLayout : UICollectionViewFlowLayout
@end
@implementation SimpleFlowLayout
- (void)prepareLayout {
...
}
- (void)prepareForCollectionViewUpdates:(NSArray *)updateItems {
...
}
- (void)finalizeCollectionViewUpdates {
...
}
- (UICollectionViewLayoutAttributes *)
initialLayoutAttributesForAppearingItemAtIndexPath:
(NSIndexPath *)itemIndexPath {
...
}
- (UICollectionViewLayoutAttributes *)
finalLayoutAttributesForDisappearingItemAtIndexPath:
(NSIndexPath *)itemIndexPath {
...
}
@end
As an item is added to UICollectionView
, reloadData
is called. ReloadData
does always reinitialize the layout, thus it will call prepareLayout
again and again, and will never call prepareForCollectionViewUpdates
at all.
Do you have any idea how to handle it?
Solved, I had to use batchUpdate instead of reloadData in textFieldShouldReturn method.