【问题标题】:Cannot assign a value of type '[UIImage?]' to a value of type 'String'无法将“[UIImage?]”类型的值分配给“String”类型的值
【发布时间】:2017-07-02 03:23:29
【问题描述】:

我正在尝试调用图像,但出现错误“无法分配 'UIImage 类型的值?'输入“字符串””,我会很感激你的帮助。

 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'

}

【问题讨论】:

  • 明显的问题是 detail view.pic 没有定义为 UIImage,而是定义为字符串。如何纠正它?需要更多代码。
  • 请提供问题根源的代码,即定义self.imagesdetailview.pic的代码。

标签: ios swift xcode uiimage tableview


【解决方案1】:

可能那张图片是来自detailview.pic.的String类型

【讨论】:

  • 是的,当时是凌晨 3 点,我想它是 >> 无法将 String 类型的值分配给 UIImage 类型的值,所以这个答案不成立。我会更新的。
猜你喜欢
  • 1970-01-01
  • 2015-10-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多