0
在定義爲我的自定義視圖控制器如下:爲什麼sizeForItemAtIndexPath永遠不會被調用?
class Wall : UIViewController, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, WallLayoutDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let layout = WallLayout()
layout.delegate = self
let collectionView = UICollectionView(frame: view.bounds, collectionViewLayout: layout)
collectionView.registerClass(WallCell.self, forCellWithReuseIdentifier: Wall.reuseIdentifier)
collectionView.delegate = self
collectionView.dataSource = self
collectionView.backgroundColor = UIColor.blackColor()
self.view.addSubview(collectionView)
self.collectionView = collectionView
}
// CODE
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
return CGSizeMake(50, 100)
}
}
功能sizeForItemAtIndexPath不會被調用。它是如何來的?
它調用numberOfSectionsInCollectionView和numberOfItemsInSection? –
如果這兩個中的任何一個返回0,那麼sizeForItemAtIndexPath將不會被調用。 –