ios개발/프로젝트
<ios 프로젝트2> UICollectionView by Code
studying develop
2020. 3. 21. 17:17
[https://itnext.io/programmatic-custom-collectionview-cell-subclass-in-swift-5-xcode-10-291f8d41fdb1]
그냥 이대로 하면 된다.
한가지 몰라서 실수 한 부분은
cv.register(UICollectionViewcell.self , forCellWithReuseIdentifier: "cell")
콜렉션 뷰에 셀을 등록 안하면
func collectionView( _ collectionView : UICollectionView, cellForItemAt indexPath : IndexPath) -> UICollectionViewCell{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! CustomCell
cell.backgroundColor = .red
return cell
}
이 함수 호출시 에러가 난다.
근데 난 cell 식별자가 없다고 생각해서 레지스터를 안했는데, 그래도 해야된다.