集合视图一次仅加载一个单元格

时间:2020-04-17 03:25:56

标签: swift loading collectionview indexpath

已编辑

我正在使用自定义收集单元格加载到collectionview中。但是,当集合视图加载预期的行为时,cellforindex代表将调用3个indexpath,但在这种情况下,仅调用3个第0个indexpath。

    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

    }

1 个答案:

答案 0 :(得分:0)

全部检查

  1. self.arrIds.count = 3
  2. numberOfSections = 1
  3. numberOfItemsInSection
  4. cellForItemAt
相关问题