我使用以下代码比较两个字符串,并根据比较显示不同的图像:
let sameQuotation = "0"
if prioridad == sameQuotation {
print("es 0-")
let image11 = UIImage(named: "pri0") as UIImage?
}
let sameQuotation1 = "1"
if prioridad == sameQuotation1 {
print("es 1-")
let image11 = UIImage(named: "pri1") as UIImage?
}
“打印”动作完美无缺,但图像不会改变。
我是Swift的新手,可能是我的代码出了问题。
谢谢。
答案 0 :(得分:4)
它没有改变,因为你在每个条件中重新声明image11
。将let image11 = ...
更改为image11 = ...
以访问我之前声明的image11
版本,例如:
if prioridad == sameQuotation {
print("es 0-")
image11 = UIImage(named: "pri0") as UIImage?
}
let sameQuotation1 = "1"
if prioridad == sameQuotation1 {
print("es 1-")
image11 = UIImage(named: "pri1") as UIImage?
}