【发布时间】:2021-10-28 17:49:30
【问题描述】:
我有这个创建图像的代码:
func getImage() -> Image {
if coupons[index].image.isEmpty {
return Image(systemName: "tag")
}
else {
return Image(uiImage: UIImage(data: coupons[index].image) ?? UIImage())
}
}
var body: some View {
getImage()
}
coupons[index].image 在同一页面的另一部分更新。我希望getImage() 在coupons[index].image 更改时更新,因为Binding 不起作用。
编辑:
coupons 是一个 State 变量,取自 UserDefaults。 index 是一个 State 变量。 coupons[index].image 使用 ImagePicker 更新。
【问题讨论】:
-
我们需要最少的可重现的问题示例
-
如果
coupons和index都是@State变量,据我所知,这应该可以正常工作。我们需要更多信息和代码 -
@CloudBalancing 我不确定这在这里是否太相关,但我们仍然需要问题中的更多信息才能知道如何提供帮助