无法将类型'[UIImage?]'的值赋给'String'类型的值

时间:2017-02-14 00:38:15

标签: ios swift xcode uiimage tableview

我正在尝试调用图像但收到错误“无法指定类型'UIImage的值?'输入'String'“我会感谢你的帮助。

 class flowerVC: UIViewController {
var label = ""
var pic = ""
var info = ""
@IBOutlet var label1: UILabel!
@IBOutlet var label2: UILabel!
@IBOutlet weak var image: UIImageView!


override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
    label1.text = label
    label2.text = info
    image.image = UIImage(named: pic)
}
override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}    

顶部的代码是自定义self.images和detailview.pic的地方,对不起,如果不是我是xcode的新手。

 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = self.tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! CustomCell

    cell.name.text = names[indexPath.row]
    cell.cost.text = flowers[indexPath.row]
    cell.photo.image = images[indexPath.row]

    return cell
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "show" {
        let indexpath = self.tableView.indexPathForSelectedRow!
        let detailview : flowerVC = segue.destination as! flowerVC
        detailview.label = self.names[indexpath.row]
        detailview.info = self.flowers[indexpath.row]
        detailview.pic = self.images[indexpath.row] //Cannot assign value of type 'UIImage?' to type 'String'

}

1 个答案:

答案 0 :(得分:-1)

可能pic是来自detailview.pic.

的字符串类型