我想爲我的UICollectionView設置UICollectionViewLayout,但是當設置圖層時,函數cellForItemAt不會被調用。我不明白爲什麼。 我UICollectionView是在廈門國際銀行,與此代碼用於測試UICollectionViewLayout:當設置了UICollectionViewLayer時,cellForItemAt不叫
required init?(coder aDecoder: NSCoder)
{
super.init(coder: aDecoder)
xibSetup()
self.collectionView.register(UINib(nibName: "StepCell", bundle: nil), forCellWithReuseIdentifier: stepCellIdentifier)
self.collectionView.delegate = self
self.collectionView.dataSource = self
}
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 3
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 100
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if let lCell = collectionView.dequeueReusableCell(withReuseIdentifier: stepCellIdentifier, for: indexPath) as? StepCell {
lCell.text.text = indexPath.row.description
return lCell
}
return UICollectionViewCell()
}
我在另一個廈門國際銀行的自定義UICollectionViewCell這是我UICollectionViewLayout類:
class DetailGroupCollectionviewLayout: UICollectionViewLayout {
let CELL_HEIGHT = 30.0
let CELL_WIDTH = 100.0
var cellAttrsDictionary = Dictionary<IndexPath,UICollectionViewLayoutAttributes>()
var contentSize = CGSize.zero
override var collectionViewContentSize: CGSize {
return self.contentSize
}
override func prepare() {
if let lCollectionView = self.collectionView {
if lCollectionView.numberOfSections > 0 {
for section in 0...lCollectionView.numberOfSections - 1 {
if lCollectionView.numberOfItems(inSection: section) > 0 {
for item in 0...lCollectionView.numberOfItems(inSection: section) - 1 {
let cellIndex = IndexPath(item: item, section: section)
let xPos = Double(item) * CELL_WIDTH
let yPos = Double(section) * CELL_HEIGHT
let cellAttributes = UICollectionViewLayoutAttributes(forCellWith: cellIndex)
cellAttributes.frame = CGRect(x: xPos, y: yPos, width: CELL_WIDTH, height: CELL_HEIGHT)
cellAttributes.zIndex = 1
cellAttrsDictionary[cellIndex] = cellAttributes
}
}
}
}
}
}
}
我已經試過有關於故事板中的UICollectionView的所有內容,因爲我認爲xib「bug」但是這不會解決任何問題。
有一件事情我不正確或特殊?我迷路了。
我上的Xcode 8.3雨燕3.1與我的應用程序是iOS上的10