在我的自定义视图控制器中定义如下:
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。它是怎么来的?
答案 0 :(得分:2)
我发现这是因为当我使用UICollectionViewDelegateFlowLayout并且无法通过集合视图推断时,布局由我决定。