티스토리 뷰

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설정합니다 delegatedatasource드래그 앤 드롭을 참조 이미지로 :

여기에 이미지 설명 입력

참고 : collectionView 관련 클래스와 함께 위의 형식을 완료하면 나타납니다.

-------------------

UICollectionView는 UITableView와 같은 정적 셀을 지원하지 않습니다. 데이터 소스를 설정하고 코드에서 셀을 위임 및 구성해야합니다.



출처
https://stackoverflow.com/questions/39916903
댓글
공지사항
Total
Today
Yesterday
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28