2017-02-14 136 views
-4

我正在尝试调用图像,但出现错误“无法赋值类型'UIImage?'的值。键入'字符串'“我会很感激的帮助。无法将类型'[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

最明显的问题是,详细view.pic没有被定义为一个的UIImage,而是作为一个字符串字符串类型。如何纠正?需要更多的代码。 – dfd

+0

请提供问题出处的代码,即定义了“self.images”和“detailview.pic”的代码。 – Antoine

回答

-1

可能是PIC是从detailview.pic.

+0

如果你阅读代码,你不会得出这个结论。 –

+0

是的,这是凌晨3点,我认为它不能>>类型的值的类型UIImage的值不能分配,所以这个答案不代表。我会更新它。 – Aragunz

相关问题