小编ben*_*661的帖子

以编程方式使UICollectionViewController不显示单元格

背景为黑色,单元格为白色,尽管任何单元格都未显示,但是没人simulator?会知道为什么会这样吗?

import UIKit
import Foundation

class ChatLog: UICollectionViewController, UITextFieldDelegate, UICollectionViewDelegateFlowLayout {

    let cellId = "cellId"

    override func viewDidLoad() {
        super.viewDidLoad()

        collectionView?.backgroundColor = UIColor.black
        collectionView?.register(UICollectionViewCell.self, forCellWithReuseIdentifier: cellId)    
    }

    override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 5
    }

    override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath)
        cell.backgroundColor = UIColor.white

        return cell
    }

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: …
Run Code Online (Sandbox Code Playgroud)

uicollectionview swift

1
推荐指数
1
解决办法
1724
查看次数

标签 统计

swift ×1

uicollectionview ×1