두 가지 유형의 셀을 사용할 때 크기 컬렉션 뷰를 결정하는 방법과 이러한 셀 중 하나의 크기는 항상 하나이지만 다른 셀의 크기는 배열에 따라 다르며 크기가 동적이기 때문입니다.
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if indexPath.row == 0 {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ProfileCell", for: indexPath) as! ProfileCollectionViewCell
cell.bioLabelText.text = bio
return cell
}else {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! CountryCollectionViewCell
cell.countryLabel.text = city
cell.imgView.image = UIImage(named: "lake.jpg")
cell.makeRounded()
return cell
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return uniqueCountryArray.count
}
내 ProfileCell 번호는 1이어야하고 다른 셀의 번호는 uniqueCountryArray.count 여야합니다. 그러나 "return uniqueCountryArray.count + 1"을 쓰면 오류가 발생합니다. "return uniqueCountryArray.count"를 쓸 때 하나의 배열 요소를 놓쳤습니다.
어떻게 모든 배열 요소를 동적으로 가져올 수 있습니까? 그리고 id 배열 크기는 0이지만 여전히 I cell이 프로필 Cell에서 온다는 것을 보여야합니다.
당신을 변경 city = uniqueCountryArray[indexPath.row]
하기 위해 city = uniqueCountryArray[indexPath.row-1]
다음과 같은
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if indexPath.row == 0 {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ProfileCell", for: indexPath) as! ProfileCollectionViewCell
cell.bioLabelText.text = bio
return cell
}
else {
let city = uniqueCountryArray[indexPath.row-1]
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! CountryCollectionViewCell
cell.countryLabel.text = city
cell.imgView.image = UIImage(named: "lake.jpg")
cell.makeRounded()
return cell
}
}
그리고 numberOfItemsInSection
될 것입니다uniqueCountryArray.count+1
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return uniqueCountryArray.count+1
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다