【问题标题】:Collection view loading only one cell at a time集合视图一次只加载一个单元格
【发布时间】:2020-07-30 11:37:13
【问题描述】:

编辑

我正在使用自定义集合单元在集合视图中加载。但是当集合视图加载预期行为时 cellforindex 委托将调用 3 个索引路径,但在这种情况下只调用第 0 个索引路径 3 次。

    override func viewDidLoad()
    {
        super.viewDidLoad()
        let nib = UINib(nibName: "cellName", bundle: nil)
        self.collectionvView?.register(nib, forCellWithReuseIdentifier: "cellId")
    }

    func numberOfSections(in collectionView: UICollectionView) -> Int
    {
        return 1
    }

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

    func collectionView(_ collectionView: UICollectionView,
              cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
    {
        print("indexpath.row ----------------- ",indexPath.row)

        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellId",for: indexPath) as! DetailCollectionViewCell
         return cell

    }

【问题讨论】:

  • 请提供一些代码
  • 发布您的collectionView(_:numberOfItemsInSection:) 方法。
  • 提供cellForRow完整代码。

标签: swift loading collectionview indexpath


【解决方案1】:

检查所有这些

  1. self.arrIds.count = 3
  2. numberOfSections = 1
  3. numberOfItemsInSection
  4. cellForItemAt

【讨论】:

  • 您好,我已经检查了所有这些步骤,数组计数为 10。
  • 在 numberOfItemsInSection 中使用 array.count 并将断点放在所有方法并检查索引 path.row 的日志
猜你喜欢
  • 2019-09-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-29
  • 2018-07-23
  • 1970-01-01
  • 2017-02-25
  • 1970-01-01
相关资源
最近更新 更多