Bootstrap

UICollectionView 的UICollectionReusableView复用 IOS18报错问题记录

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath 方法复用报错

报错详情:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Expected dequeued view to be returned to the collection view in preparation for display. When the collection view's data source is asked to provide a view for a given index path, ensure that a single view is dequeued and returned to the collection view. Avoid dequeuing views without a request from the collection view. For retrieving an existing view in the collection view, use -[UICollectionView cellForItemAtIndexPath:] or -[UICollectionView supplementaryViewForElementKind:atIndexPath:]. Dequeued view: <CmmentSearchFooterReusableView: 0x7fb3ef3262f0; baseClass = UICollectionReusableView; frame = (0 0; 440 80); clipsToBounds = YES; layer = <CALayer: 0x600002f819e0>>; Collection view: <UICollectionView: 0x7fb3f1821800; frame = (0 0; 440 772.667); clipsToBounds = YES; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x6000020cf930>; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <CALayer: 0x600002f71660>; contentOffset: {0, 0}; contentSize: {440, 80}; adjustedContentInset: {0, 0, 0, 0}; layout: <CHTCollectionViewWaterfallLayout: 0x7fb3ef51ca80>; dataSource: <RecommendationViewController: 0x7fb3f184fe00>>'

这样写法导致同一个indexPath设置了两个UICollectionReusableView,ios18就报错了,修改如下:每次调用每个indexPath位置上只有一个UICollectionReusableView。

;