对成员 'collectionView(_:layout:minimumLineSpacingForSectionAt:)' 的不明确引用 [英] Ambiguous reference to member 'collectionView(_:layout:minimumLineSpacingForSectionAt:)'

查看:38
本文介绍了对成员 'collectionView(_:layout:minimumLineSpacingForSectionAt:)' 的不明确引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的代码中发现了一个让我非常恼火的错误.我在一个单独的应用程序中编写了滑动视图控制器的代码,现在我正在尝试将它集成到这个新应用程序中.

I have found an error in my code that is really annoying me. I coded Swiping View Controller in a separate application and now I am trying to integrate it into this new application.

以下是视图控制器类的布局:

here is how view controller class is layed out:

class SwipingController: UIViewController, UICollectionViewDelegateFlowLayout {

基本上错误如下:

Ambiguous reference to member 'collectionView(_:layout:minimumLineSpacingForSectionAt:)'

这是我的一些代码,如果我需要添加更多,请告诉我!!

here is some of my code, let me know if I need to add more!!

extension SwipingController {

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
        return 0
    }

     func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return pages.count
    }

     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellId", for: indexPath) as! PageCell

        let page = pages[indexPath.item]
        //let page = pages[indexPath.row]
        cell.page = page
        return cell
    }

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        return CGSize(width: view.frame.width, height: view.frame.height)
    }

}

在主视图控制器中每次提到CollectionView"时都会发生错误

the error happens on every mention of "CollectionView" in the main view controller

 @objc private func handleNext() {
        let nextIndex = min(pageControl.currentPage + 1, pages.count - 1)
        let indexPath = IndexPath(item: nextIndex, section: 0)
        pageControl.currentPage = nextIndex
        collectionView?.scrollToItem(at: indexPath, at: .centeredHorizontally, animated: true)
    }

我现在也收到错误:

Value of type 'SwipingController' has no member 'collectionViewLayout'

在此页面上发生了什么:

Which happens on this page:

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {

        coordinator.animate(alongsideTransition: { (_) in
            self.collectionViewLayout.invalidateLayout()

            if self.pageControl.currentPage == 0 {
                self.collectionView?.contentOffset = .zero
            } else {
                let indexPath = IndexPath(item: self.pageControl.currentPage, section: 0)
                self.collectionView?.scrollToItem(at: indexPath, at: .centeredHorizontally, animated: true)
            }

        }) { (_) in

        }
    }

如果我需要添加更多代码,请告诉我!

let me know if I need to add more code in please!

推荐答案

我设法解决了几个小时的问题:

I managed to solve this by wrestling with it for a few hours:

我的主要问题是故事板中的视图控制器是视图控制器而不是集合视图控制器.

My major problem was the view controller in the storyboard was a view controller and not a collection view controller.

感谢所有帮助过的人!

这篇关于对成员 'collectionView(_:layout:minimumLineSpacingForSectionAt:)' 的不明确引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆