ฉันพบปัญหาในมุมมองคอลเลกชันในโครงการของเรา -
Collectionview ประกอบด้วย 4 ส่วน แต่ละส่วนประกอบด้วย 1 เซลล์
หากเราคงความสูงเป็นศูนย์สำหรับเซลล์มุมมองคอลเลกชันในส่วน 0 ระบบจะไม่เรียก cellforrrowatindexpath สำหรับส่วนที่เป็นศูนย์ ปัญหาที่เรากำลังเผชิญคือ cellforrowatindexapath จะไม่ถูกเรียกในส่วนต่อๆ ไปเช่นกัน มุมมองคอลเลกชันจะไม่แสดงสิ่งใดบนหน้าจอแม้ว่าจะมีการระบุความสูงของเซลล์ส่วนอื่นๆ ไว้ก็ตาม
อัปเดต:
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 3
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
Switch indexpath.section {
case 0: return CGSize(width: UIScreen.main.bounds.width, height: 0)
case 1: return CGSize(width: UIScreen.main.bounds.width, height: 200)
case 2: return CGSize(width: UIScreen.main.bounds.width, height: 300)
}
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
Switch indexpath.section {
case 0: return A()
case 1: return B()
case 2: return C()
}
}
หากใครมีความเข้าใจมากขึ้นว่าเหตุใดมุมมองคอลเลกชันจึงทำงานในลักษณะนี้ โปรดแจ้งให้เราทราบ