Reputation: 430
I have a problem changing the Layout of UICollectionView from Flow to Custom.
I referenced the address "https://www.raywenderlich.com/392-uicollectionview-custom-layout-tutorial-pinterest"
I tried adding the example code to the existing code
override func viewDidLoad ()
{
super.viewDidLoad ()
self.setViewLayer ()
self.addPullToRefresher ()
self.addGesture ()
self.addDropDownView ()
self.getArtList ()
self.artCollectionView.regCells (cells: ["HomeCollectionViewCell"])
NotificationCenter.default.addObserver(self, selector: #selector(self.getNotification(_:)), name: Notification.Name(Constants.GET_ARTS), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(self.resetArts(_:)), name: Notification.Name(Constants.GET_ARTS_RESET), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(self.searchArts(_:)), name: Notification.Name(Constants.HOME_SEARCH), object: nil)
if let layout = collectionView?.collectionViewLayout as? PinterestLayout
{
layout.delegate = self
}
}
extension HomeViewController: PinterestLayoutDelegate
{
func collectionView (_ collectionView: UICollectionView, heightForPhotoAtIndexPath indexPath: IndexPath) -> CGFloat
{
return photos [indexPath.item].image.size.height
}
}
But I am getting an error at
collectionView?.collectionViewLayout as? PinterestLayout
Error states
Ambiguous reference to member 'collectionView (_: willDisplay: forItemAt :)'
Please help me.
Upvotes: 0
Views: 914
Reputation: 318884
Based on other code in viewDidLoad
, your collection view variable is named artCollectionView
, not collectionView
. The error is really misleading in this case.
Change:
if let layout = collectionView?.collectionViewLayout as? PinterestLayout
to:
if let layout = artCollectionView.collectionViewLayout as? PinterestLayout
Upvotes: 1