0
次は私のコードです:NSInternalInconsistencyExceptionエラー
import UIKit
class FriendsController: UICollectionViewController {
private let cellId = "cellId"
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
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell{
return collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath as IndexPath)
}
}
class FriendCell: UICollectionViewCell {
override init(frame: CGRect) {
super.init(frame: frame)
setUpViews()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setUpViews() {
backgroundColor = UIColor.blue
}
}
そして、次は私のエラーです:
Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: 'the collection view's data source did not return a valid cell from
-collectionView:cellForItemAtIndexPath: for index path
<NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}'
は私が間違っていたものにと正確にはわかりませんか?誰かが私のエラーとそれを修正する方法の両方を説明するのを助けることができれば、それは非常に高く評価されるだろう。私はまだSwiftにとっては少し新しく、これは私の最初のエラーです。特に私のコードの文脈では理解できませんでした。
あなたはスウィフト3データソースの方法ではなく、スウィフト2つの方法を提供する必要があります。 – rmaddy
それはどういう意味ですか?私が言ったように、私はスウィフトの新人です。 –