총 4 개의 (0, 1, 2, 3) 섹션이있는 사용자 지정 UICollectionView가 있습니다. 내가하고있는 일은 section 2
을 표시 할 정보가 없으면이 섹션의 셀 크기를 CGSize(width: view.bounds.width, height: 0)
으로 설정한다는 것입니다. 문제는 섹션 3의 셀이 심지어 CGSize(width: view.bounds.width, height: 50)
이 section 3
에 대한 스위치에 sizeForItemAtIndexPath
에서 호출되었다고 생각하는 경우에도 표시되지 않습니다.CollectionView에 마지막 섹션이 표시되지 않습니다.
지금까지 발견 한 내용은 내 switch
의 cellForItemAtIndexPath
과 case 2 and 3
이이 경우에 호출되지 않습니다.
section 2
에서 return 0
까지의 셀을 설정하면 section 3
이 표시된다는 것을 발견했습니다.
내가 실종되었다고 생각하는 것은 layout
에 내가 잘못하고있는 것입니다 ... 어쩌면 당신 중 하나가 전에 이것을 경험했습니다.
다음은 제 코드입니다.
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
switch indexPath.section {
case 0: return CGSize(width: view.bounds.width, height: 50)
case 1: return CGSize(width: view.bounds.width, height: 75)
case 2:
if let description = description , description.characters.count > 0 {
let sizingNibNew = NSBundle.mainBundle().loadNibNamed("BioCollectionViewCell", owner: BioCollectionViewCell.self, options: nil)
let sizingCellNew = sizingNibNew?[0] as! BioCollectionViewCell
sizingCellNew.myText = description
sizingCellNew.initialize()
return CGSize(width: view.bounds.width, height: sizingCellNew.myTextView.frame.height + 10)
} else {
return CGSize(width: view.bounds.width, height: 0)
}
case 3:
return CGSize(width: view.bounds.width, height: 50)
default:
return CGSize(width: view.bounds.width, height: 0)
}
}
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 4
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
switch section {
case 0: return 4
case 1: return 1
case 2: return 1
case 3: return 2
default:
return 0
}
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
switch indexPath.section {
case 0:
switch indexPath.item {
case 0:
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("MapView", forIndexPath: indexPath) as! MapView
if let address = address, let city = city {
cell.setAddressInMapView(address, cityAddress: city)
}
return cell
case 1:
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("TitleCell", forIndexPath: indexPath) as! TitleCell
cell.titleLabel.text = title1
return cell
case 2:
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("NameCell", forIndexPath: indexPath) as! NameCell
cell.nameLabel.text = xName
return cell
case 3: // address
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("AddressCell", forIndexPath: indexPath) as! AddressCell
cell.addressLabel.text = address
return cell
default:
return UICollectionViewCell()
}
case 1:
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Name", forIndexPath: indexPath) as! ShowFeaturedArtist
cell.xId = id ?? ""
cell.nameLabel.text = name ?? ""
cell.populateViewWithoutQuery()
return cell
case 2:
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("BioCollectionViewCell", forIndexPath: indexPath) as! BioCollectionViewCell
if let description = description where description.characters.count > 0 {
cell.myText = description
}
cell.initialize()
return cell
case 3:
switch indexPath.item {
case 0:
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("UserAttending", forIndexPath: indexPath) as! UserAttending
cell.label.text = "0 " + " Users Attending"
return cell
case 1:
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("UserAttending", forIndexPath: indexPath) as! UserAttending
cell.label.text = "Release Dates"
return cell
default:
return UICollectionViewCell()
}
default:
return UICollectionViewCell()
}
}
이슈 무엇입니까? 'section-2'에 표시 할 데이터가 없으므로 높이를 0으로 놓고'cellAtItem'은 그걸 ok라고 부르지 않습니다. 'height = 0'을 넣으면 컴파일러가 무엇을 기대하는지 ........ CPU주기를 낭비하기 위해'cellForItem'을 실행합니다. –
문제는 '섹션 2'에 데이터가 없으면 섹션 3이 표시되지 않는다는 것입니다. – John
섹션 3이 섹션 2에오고 콜렉션 뷰를 다시로드하는 방식으로 데이터 소스를 만듭니다. – Koushik