简体   繁体   中英

Value Of Type UIView Has No Member Error

I keep getting this error in my code it says Value Of Type UIView Has No Member.

Here is the code.

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
}

The problematic code is this,

cell.cellImage.image = imageName

Here is the cellLemon class. Just what you guys asked for.

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
}

}

You are wrong at this. Please double check, and fix it

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

It appears the tableView can't find an imageView property in your custom cell. Does your custom cell have an imageView that is hooked up to an outlet, and is it named cellImage?

Edit: thanks for the update, found the issue. Your cellImage in your cell is a UIView (not an ImageView). If you want to display an image there, it either must contain and imageView or be an actual imageView.

In your code you are trying to assign an image to a UIVIew (cellImage). It is not possible to assign an image directly to an UIView.

Try this.

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

All you need to use is:

self.view.backgroundColor = UIColor(patternImage: UIImage(named: "ImageName"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM