When implementing a simple segment using the collectionView pure code frame layout, we encountered a problem that the page layout was not refreshed after reloadData. The problem is small, but always ignored, so record

In the first page implementation number of 2 display normal

However, the size of the cell is not refreshed when the data is switched to 1

At the break point everything in numberOfItemsInSection, cellForItemAtIndexPath, or sizeForItemAtIndexPath is displayed normally

After the test, it was found that the layout in the cell was related to the simple content, so I would not use the navigation method. In init, the layout was only realized by the frame method, which was pure code. After the collectionView was reload, the layout method could not update the page layout

Therefore, you can solve this problem by implementing the layout in layoutSubviews or using the navigation layout

- (void)layoutSubviews{ [super layoutSubviews]; _itemBtn.func_frame(self.bounds); _itemSeg. Func_frame (CGRectMake (self. Width - 0.25, 0, 0.5, and the self. The width)); }Copy the code

ReloadSections :[NSIndexSet indexSetWithIndex: ] method can also solve issues related to the precise reload item | section will be effective to refresh the specified content or direct call setNeedsLayout also refresh effect can be realized