2017-07-30 11 views
-1

最初に私はストーリーボードを使用していません。これはすべてプログラムで行います。呼び出されていない。それは何が原因でしょうか?スウィフトコレクションビューコントローラーのセルが表示されず、アイテムのセルが呼び出されていない

import UIKit 

class ChatLOGVC: UICollectionViewController { 

    private let cellId = "Cell" 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     collectionView?.backgroundColor = UIColor.red 

     collectionView?.register(FriendCell.self, forCellWithReuseIdentifier: cellId) 
    } 

    override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 
     return 3 
    } 

    override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 
     print("cell for item at index path called") 
     return collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath) 
    } 

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { 
     return CGSize.init(width: view.frame.width, height: 80) 
    } 
} 

class FriendCell: UICollectionViewCell { 
    override init(frame: CGRect) { 
     super.init(frame: frame) 
     backgroundColor = UIColor.blue 
    } 

    required init?(coder aDecoder: NSCoder) { 
     fatalError() 
    } 
} 
+0

あなたはレイアウトパラメータを使用してコレクションVCを初期化しますか? – Phyber

+0

@Phyber - UICollectionViewDelegateFlowLayoutを追加すると、全く同じ結果が得られます。/何もしませんか? – bennypalmer661

+0

ストーリーボードを使用していますか? – Phyber

答えて

0

あなたは、このようなレイアウトであなたのコレクションVCを提示する必要があります。

let layout = UICollectionViewFlowLayout() 
layout.sectionInset = UIEdgeInsets(top: 20, left: 10, bottom: 10, right: 10) 
let to_chat_controller = ChatLOGVC(collectionViewLayout: layout) 
+0

OMG!おかげさまで、数日間それが続いています! – bennypalmer661

関連する問題