0
我想在UIViewcontroller中使用UICollectionView,並有一些問題...不知道我在做什麼錯?我將故事板中的UICOllectionView設置爲dataSource和委託,但仍然出現錯誤...感謝您提供任何幫助!在UIViewController中的UICollectionView
class AlbumViewController: UIViewController, UICollectionViewDelegate {
let collectionViewA = UICollectionView()
let collectionViewAIdentifier = "AlbumCell"
override func viewDidLoad() {
super.viewDidLoad()
// Initialize the collection views, set the desired frames
collectionViewA.delegate = self
collectionViewA.dataSource = self
self.view.addSubview(collectionViewA)
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
if collectionView == self.collectionViewA {
let cellA = collectionView.dequeueReusableCellWithReuseIdentifier(collectionViewAIdentifier) as UICollectionViewCell
// Set up cell
return cellA
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if collectionView == self.collectionViewA {
return 0 // Replace with count of your data for collectionViewA
}
return 0 // Replace with count of your data for collectionViewB
}
}
但還是收到錯誤添加該代碼。什麼樣的錯誤?在這裏打印它們。 Muku已經提到過在viewdidLoad中註冊單元格。 –