UIView类型的值没有成员错误

时间:2016-03-08 04:47:43

标签: ios swift uiview

我在我的代码中不断收到此错误,它表示UIView类型的值没有成员。

这是代码。

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cell: CellLemon = tableView.dequeueReusableCellWithIdentifier("Cell") as! CellLemon

    cell.cellTopLabel.text = CarMake[indexPath.row]

    cell.cellBottom.text = CarModel[indexPath.row]

    var imageName = UIImage(named: CarImage[indexPath.row])

    cell.cellImage.image = imageName



    // Configure the cell...

    return cell
}

有问题的代码就是这个,

cell.cellImage.image = imageName

这是cellLemon类。正是你们要求的。

import UIKit

class CellLemon: UITableViewCell {


@IBOutlet weak var cellImage: UIView!

@IBOutlet weak var cellTopLabel: UILabel!

@IBOutlet weak var cellBottom: UILabel!


override func awakeFromNib() {
    super.awakeFromNib()
    // Initialization code
}

override func setSelected(selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)

    // Configure the view for the selected state
}

}

3 个答案:

答案 0 :(得分:1)

你错了。请仔细检查并修复它

@IBOutlet weak var cellImage: UIView! // why cellImage is UIView?

答案 1 :(得分:0)

看来tableView无法在自定义单元格中找到imageView属性。您的自定义单元格是否具有连接到插座的imageView,它是否命名为cellImage?

编辑:感谢您的更新,发现了问题。单元格中的cellImage是UIView(不是ImageView)。如果要在那里显示图像,它必须包含和imageView或者是实际的imageView。

答案 2 :(得分:0)

在您的代码中,您尝试将图像分配给UIVIew(cellImage)。无法将图像直接分配给UIView。

试试这个。

let cell: CellLemon = tableView.dequeueReusableCellWithIdentifier("Cell") as! CellLemon
var imageName = UIImage(named: CarImage[indexPath.row])
cell.cellImage.backgroundColor = UIColor(patternImage: imageName)

您需要使用的是:

self.view.backgroundColor = UIColor(patternImage: UIImage(named: "ImageName"))
相关问题