티스토리 뷰
collectionView
아래 코드와 이미지를 올바르게 구성 하십시오.
다음 delegate
방법을 구현합니다 collectionView
.
class yourClassController: UICollectionViewDataSource, UICollectionViewDelegate {
override func numberOfSectionsInCollectionView(collectionView:
UICollectionView!) -> Int {
return 1
}
override func collectionView(collectionView: UICollectionView!,
numberOfItemsInSection section: Int) -> Int {
return yourArray.count
}
override func collectionView(collectionView: UICollectionView!,
cellForItemAtIndexPath indexPath: NSIndexPath!) ->
UICollectionViewCell! {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("CollectionViewCell", forIndexPath: indexPath) as CollectionViewCell
// Configure the cell
cell.backgroundColor = UIColor.blackColor()
cell.textLabel?.text = "\(indexPath.section):\(indexPath.row)"
cell.imageView?.image = UIImage(named: "circle")
return cell
}
그런 다음에서 storyboard
설정합니다 delegate
및 datasource
드래그 앤 드롭을 참조 이미지로 :
참고 : collectionView
관련 클래스와 함께 위의 형식을 완료하면 나타납니다.
UICollectionView는 UITableView와 같은 정적 셀을 지원하지 않습니다. 데이터 소스를 설정하고 코드에서 셀을 위임 및 구성해야합니다.
출처
https://stackoverflow.com/questions/39916903
댓글