在使用collectionView.scrollToItem并导致崩溃[UICollectionViewData layoutAttributesForItemAtIndexPath:]

时间:2018-03-01 08:37:00

标签: swift uicollectionview

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

    //获取滤镜信息
    let lastCell = collectionView.cellForItem(at: lastSelectIndex!) as? FilterListViewCell
    lastCell?.isSelect = false

    var filters : Array<GPUImageFilter> = []
    let cell = collectionView.cellForItem(at: indexPath) as? FilterListViewCell
    if (lastSelectIndex == indexPath) {
        cell?.isSelect = false
        lastSelectIndex = IndexPath.init(row: -1, section: -1)
        currentFilterInfo = nil
    }else {
        filterDelegate?.didbeganApplyFilter()
        cell?.isSelect = true
        let filterInfo = filterManager.configArray[indexPath.section].filterInfos[indexPath.row]
        filters = getFilters(filterInfo: filterInfo)
        lastSelectIndex = indexPath
        currentFilterInfo = filterInfo
    }

    collectionView.scrollToItem(at: indexPath, at: UICollectionViewScrollPosition.centeredHorizontally, animated: true)
    filterDelegate?.applyFilter(filters: filters)
}

我很确定它已经布局了。并且错误信息就像打击一样。

  

0x187283e6c - [UICollectionViewData   layoutAttributesForItemAtIndexPath:] + 244 1 UIKit
  0x187495144 - [UICollectionView   scrollToItemAtIndexPath:atScrollPosition:animated:] + 260 2   MagicCamera 0x10002c8a0专业   FilterListView.collectionView(UICollectionView,didSelectItemAt:   IndexPath) - &gt; ()(FilterListView.swift:156)3 MagicCamera
  0x100029bd8 @objc FilterListView.collectionView(UICollectionView,   didSelectItemAt:IndexPath) - &gt; ()(FilterListView.swift)4 UIKit
  0x187456414 - [UICollectionView   _selectItemAtIndexPath:animated:scrollPosition:notifyDelegate:] + 608 5 UIKit 0x187455d58 - [UICollectionView   touchesEnded:withEvent:] + 540 6 UIKit
  0x1873c3458 forwardTouchMethod + 336 7 UIKit
  0x1874110f8 - [UIResponder touchesEnded:withEvent:] + 60 8 UIKit
  0x1873c3458 forwardTouchMethod + 336

0 个答案:

没有答案