简体   繁体   中英

collectionView(collectionView, didSelectItemAt: indexPath) - Cannot call value of non-function type 'UICollectionView

I have a collectionView. I have its dataSource and delegate methods set and I call func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { } when the user first makes a selection which works fine.

If the user leaves the view controller and comes back to it I call the below methods in viewWillAppear to programmatically force cell selection and scroll back to the cell that was initially chosen.

let whateverCellWasChosen = 29
let indexPath = IndexPath(item: whateverCellWasChosen, section: 0)

collectionView.scrollToItem(at: indexPath, at: .centeredHorizontally, animated: false)
collectionView.selectItem(at: indexPath, animated: false, scrollPosition: .centeredHorizontally)

// problem is here
collectionView(self.collectionView, didSelectItemAt: indexPath)

But when trying to call the manual version of didSelectItem I keep getting an error of:

Cannot call value of non-function type 'UICollectionView'

在此处输入图片说明

The error stems from the first argument that accepts the collectionView. Why is it giving me a problem?

采用

collectionView.delegate?.collectionView!(collectionView, didSelectItemAt: indexPath)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM