我正在使用以下代码比较两个字符串,并根据比较显示不同的图像:
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?
}
Run Code Online (Sandbox Code Playgroud)
“打印”操作可以完美完成,但是图像不会改变。
我是Swift的新手,可能我的代码有问题。
谢谢。
它没有改变,因为您要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?
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1321 次 |
| 最近记录: |