ios18 崩溃2024-11-15

2024-11-14  本文已影响0人  iOS打怪升级

**** 崩溃代码:

   NSInteger lastY = 0;
        NSInteger section = MAX(self.firstArray.count-1, 0);
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:section];
        UICollectionReusableView *view = [self.collectionView.dataSource collectionView:self.collectionView viewForSupplementaryElementOfKind:UICollectionElementKindSectionHeader atIndexPath:indexPath];
        lastY = view.hq_y;
        
        UIEdgeInsets insets = self.collectionView.contentInset;
        insets.bottom = self.collectionView.hq_height - (self.collectionView.contentSize.height-lastY);
//        insets.left = 15;
        self.collectionView.contentInset = insets;

解决方法:collection 的回调方法之外不要试图去根据indexPath获取cell ,不过可以间接的去获取,比如下面的方法

        NSIndexPath *indexPath = [NSIndexPath indexPathForItem:0 inSection:section];
        UICollectionViewLayoutAttributes *attributes = [_collectionView layoutAttributesForItemAtIndexPath:indexPath];
        lastY = attributes.frame.origin.y;
上一篇 下一篇

猜你喜欢

热点阅读