gpt4 book ai didi

swift - 一次只显示数据库中的一张图片(Swift 和 Firebase)

转载 作者:行者123 更新时间:2023-11-28 07:59:03 24 4
gpt4 key购买 nike

首先,我是新手,所以请不要取笑我:)

基本上,我正在尝试展示产品的图片,但如果客户拒绝该产品,则该项目将不会出现在他的帐户中。这就是我创建另一个表 Rejected (setAcceptedOrRejected) 的原因,我将产品 ID 和客户 ID 放在其中,这样我就不会看到他之前拒绝的项目。

我在这里尝试的是获取包含所有项目的列表(好)和包含被拒绝项目的(差)。然后比较它以再次显示该项目的图片。

我的问题是我当时只想显示一张图片,如果客户端拒绝,它将显示下一张,依此类推,但不会再次显示该图片。

我希望你真的能帮我解决这个问题。

谢谢

func updateImage() {

createListProductsBad ()

var badnot = ""

for bad2 in listProductsBad{
badnot = bad2

}


Database.database().reference().child("Products").child(bad2)queryOrderedByKey().observe(.childAdded, with: { snapshot in

let userInfo = snapshot.value as! NSDictionary

let storageRef = Storage.storage().reference(forURL: profileUrl)
storageRef.downloadURL(completion: { (url, error) in
do {
let data = try Data(contentsOf: url!)
let image = UIImage(data: data as Data)
self.productPhoto.image = image

}
catch _ {
print("error")
}




})

})


}

func setAcceptedOrRejected() {

let notThankyou = [ "ProductID": ProductId,
"UserID": userUID
] as [String : Any]
self.storyboard?.instantiateViewController(withIdentifier: "Home")
self.refProducts.child("Rejected").childByAutoId().setValue(notThankyou)
}

func createListProductsGood () {

Database.database().reference().child("Products").queryOrderedByKey().observe(.childAdded, with: { snapshot in

if !snapshot.exists() { return }



let userInfo = snapshot.value as! NSDictionary

let goodID = String(snapshot.key)


for prod in self.listProductsBad{

if (prod == goodID){
print("Not good **********************")

}else{

if (goodID != "" ){
self.listProductsGood.append(prod)
}


}


}
})

}


func createListProductsBad () {

Database.database().reference().child("Rejected").queryOrderedByKey().observe(.childAdded, with: { snapshot in

let userInfo = snapshot.value as! NSDictionary
let currentID = userInfo["UserID"] as! String
let badProduct = userInfo["ProductID"] as! String

if (self.userUID == currentID ){

self.listProductsBad.append(badProduct)

}
})

}

最佳答案

 //These can also be swift's dictionaries, [String: AnyObject] or possibility arrays if done correctly. All depends on your style of programming - I prefer NSDictionaries just because.

let availableKeys: NSMutableDictionary = [:]
let rejectedKeys: NSMutableDictionary = [:]

//Might be a better way for you. Depends on what you are looking for.
func sortItems2() -> NSMutableDictionary{
for rejKey in rejectedKeys.allKeys{
//Removes if the rejected key is found in the available ones
availableKeys.remove(rejKey)
}
return availableKeys
}

关于swift - 一次只显示数据库中的一张图片(Swift 和 Firebase),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47193485/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com