0
我在我的主視圖中嵌入了一個UICollection View,並且我試圖給它提供已經下載並放入數組的數據。然而,CollectionView委託,它是在主VC中的一個單獨的類上定義的,似乎沒有運行。有人不能指出我做錯了什麼嗎?嵌入式UICollectionView無法從主UIViewController訪問
let reuseIdentifier = "Cell"
class DiarioCollectionView: UICollectionView, UICollectionViewDelegate, UICollectionViewDataSource {
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if defaults.boolForKey("gotPL") {
print(defaults.arrayForKey("playlistTitles")!.count) //This is not being called..
return defaults.arrayForKey("playlistTitles")!.count
}
print("No Data") //This is also not being called..
return 0
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath)
print(indexPath)
print(indexPath.item)
print(indexPath.row)
if defaults.boolForKey("gotPL") {
let thumbIV = cell.viewWithTag(1) as! UIImageView
let playTitle = cell.viewWithTag(2) as! UILabel
thumbIV.image = UIImage(data: defaults.arrayForKey("playlistThumbnails")![indexPath.row] as! NSData)
playTitle.text = defaults.arrayForKey("playlistTitles")![indexPath.row] as? String
return cell
}
return cell
}
}
(UICollectionView定義爲類DiarioCollectionView的實例,我的主視圖控制器內)
BabyShung是正確的,你的看法控制器應成爲委託人,而不是收集視圖本身。 – Darko
對!謝謝..! –