Свифт 4.
Я хочу вернуть две ячейки в одном разделе, поэтому в моем классе CollectionViewController
я делаю:
override func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1 }
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 2 }
Я вижу две ячейки, но если я печатаю indexPath.row в приведенном ниже коде (все еще в том же классе), я вижу 0 1 0 1
. Почему это не только один 0 1
, поскольку у меня есть только две ячейки в одном разделе?
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! CollectionViewCell
print(indexPath.row)
return cell
}