collectionView에 등록 했음에도 불구하고 두 번째 셀을 표시 할 수 없습니다. 누구나 이것이 왜 그런지 알 수 있습니까? 다른 셀이 대신 표시하는 행을 전환 할 때 셀이 존재합니다.Swift로 여러 UICollectionViewCell을 표시 할 수 없습니다.
class ViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout {
override func viewDidLoad() {
super.viewDidLoad()
collectionView?.backgroundColor = UIColor.white
collectionView?.register(HeaderCell.self, forCellWithReuseIdentifier: "HeaderCell")
collectionView?.register(SummaryCell.self, forCellWithReuseIdentifier: "SummaryCell")
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if section == 0 {
return 1
}
return 1
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if (indexPath.row == 0) {
let cell1 = collectionView.dequeueReusableCell(withReuseIdentifier: "HeaderCell", for: indexPath) as! HeaderCell
return cell1
} else {
let cell2 = collectionView.dequeueReusableCell(withReuseIdentifier: "SummaryCell", for: indexPath) as! SummaryCell
return cell2
}
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: view.frame.width, height: 200)
}
}
가 나는 일을 얻을 수있는 this하지만 여전히 수 없습니다를 보았다.
P. 프로그래밍 방식으로 모든 것을 프로그래밍하고 있습니다.
얼마나 많은 세포 컬렉션보기
indexPath.section
에 그러나 나는 다음은 추가하여 제대로 작동하려면 얻을 수있는 제안의 일부를 사용 했습니까? __1__을 (를) 가지고 있으므로 'HeaderCell'이 (가) 나타납니다. – holex@Chace 다른 셀이 대신 표시하는 행을 전환하면 셀이 존재합니다. 설명해 주시겠습니까? –
순간에 두 개의 셀 – Chace