です。これはImageController(ViewController)のクラスです コレクションビューの背景は表示されません。どんな助け?私が正しく初期化していないものはありますか?ここでUICollectionViewの背景が表示されていない間は、UICollectionViewのセルは
クラスです:
class ImageController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
let reuseIdentifier = "imageCell"
@IBOutlet weak var collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 10
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath as IndexPath) as! ImageCell
cell.myImage.image = unknown //name of image, isn't the cause of error
return cell
}
}
実際にデリゲートとデータソースを割り当てましたか?私はVCが両方に準拠するように設定されていると思うが、 'collectionView.delegate = self'と' collectionView.dataSource = self'といっしょにしなければならない。 – Pierce