UICollectionView单元格未显示

时间:2016-12-05 08:37:42

标签: ios swift swift3

在我的UICollectionView中,不显示单元格。我怎样才能解决这个问题?请帮帮我。

运行模拟器时未显示UICollectionView

collectionViewController.swift

var dataset = [
    ("img1.jpeg", "img2.jpeg", "img3.jpeg", "AAA", "ENNNS", "14500", "29000", "50% SALE")
lazy var list : [listVO] = {
    var datalist = [listVO]()

    for (userIconImage, productImage, saleImage, userName, productName, saledPrice, price, perSale) in self.dataset {
        let listvo = listVO()

        listvo.userIconImage = userIconImage
        listvo.productImage = productImage
        listvo.saleImage = saleImage
        listvo.userName = userName
        listvo.productName = productName
        listvo.saledPrice = saledPrice
        listvo.price = price
        listvo.perSale = perSale

        datalist.append(listvo)

    }

    return datalist
}()

override func viewDidLoad() {
    super.viewDidLoad()

    self.collectionView!.register(uCollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)

    collectionView!.delegate = self
    collectionView!.dataSource = self
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
}

override func numberOfSections(in collectionView: UICollectionView) -> Int {
    return 1
}

override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return self.list.count
}

override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! uCollectionViewCell


    let row = self.list[indexPath.row]

    cell.userName?.text = row.userName
    cell.productName?.text = row.productName
    cell.saledPrice?.text = row.saledPrice
    cell.price?.text = row.price
    cell.perSale?.text = row.perSale

    return cell
}

collectionViewCell.swift

@IBOutlet weak var userIconImage: UIImageView!
@IBOutlet weak var productImage: UIImageView!
@IBOutlet weak var saleImage: UIImageView!
@IBOutlet weak var userName: UILabel!
@IBOutlet weak var productName: UILabel!
@IBOutlet weak var saledPrice: UILabel!
@IBOutlet weak var price: UILabel!
@IBOutlet weak var perSale: UILabel!

listVO.swift

var userIconImage: String?

var productImage: String?

var saleImage: String?

var userName: String?

var productName: String?

var saledPrice: String?

var price: String?

var perSale: String?

cell

cell datasource, delegate

0 个答案:

没有答案