问题描述
所以我有这个代码,我从 firestore 获取一个 url,然后将它附加到一个数组中,然后将其存储在 userDefaults 中(临时)。
在视图中,我基本上只是遍历存储在 userdefaults 中的数组并显示图像。
但问题是,我必须在图像显示之前重新渲染视图。 我该如何解决这个问题?
struct PostedImagesView: View {
@State var imagesUrls : [String] = []
@ObservedObject var postedImagesUrls = ProfileImages()
var body: some View {
VStack{
ScrollView{
ForEach(postedImagesUrls.postedImagesUrl,id: \.self) { url in
ImageWithURL(url)
}
}
}
.onAppear{
GetImage()
print("RAN GETIMAGE()")
}
}
// Get Img Url from Cloud Firestore
func GetImage() {
guard let userID = Auth.auth().currentUser?.uid else { return }
let db = Firestore.firestore()
db.collection("Users").document(userID).collection("PostedImages").document("ImageTwoTester").getDocument { (document,error) in
if let document = document,document.exists {
// Extracts the value of the "Url" Field
let imageUrl = document.get("Url") as? String
UserDefaults.standard.set([],forKey: "postedImagesUrls")
imagesUrls.append(imageUrl!)
UserDefaults.standard.set(imagesUrls,forKey: "postedImagesUrls")
} else {
print(error!.localizedDescription)
}
}
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)