我正在尝试调用图像但收到错误“无法指定类型'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'
}
答案 0 :(得分:-1)
可能pic是来自detailview.pic.