gpt4 book ai didi

ios - 我在一个页面上显示所有用户的图片和教育,如何从列表中删除当前用户?

转载 作者:行者123 更新时间:2023-11-28 05:41:03 26 4
gpt4 key购买 nike

由于当前用户不关心他的信息,只关心其他人的信息,他必须被排除在列表之外。我读过核心数据 fetchrequest 可用于此目的,但我不确定如何以及在何处合并 NSFetchRequest。

我曾尝试在不同的地方使用 NSFetchRequest,但我得到 Class methods may only be declared on a type 错误。

///上游

public override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {


return people.count

}

public override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! ViewControllerTableViewCell

let immy = cell.viewWithTag(1) as! UIImageView

let person: Userx = people[indexPath.row]

cell.lblName.text = person.Education

if let PhotoPosts = person.PhotoPosts {
let url = URL(string: PhotoPosts)
immy.sd_setImage(with: url)
}

return cell
}

////下游

refArtists = Database.database().reference().child("people");

refArtists.observe(DataEventType.value, with: {snapshot in

if snapshot.childrenCount>0{

self.people.removeAll()

for people in snapshot.children.allObjects as! [DataSnapshot] {
let peopleObject = people.value as? [String: AnyObject]
let peopleEducation = peopleObject?["Education"] as? String
let peoplePhotoPosts = peopleObject?["PhotoPosts"] as? String
let peopl = Userx(Education: peopleEducation, PhotoPosts: peoplePhotoPosts)
self.people.append(peopl)

}
self.table.reloadData()
print(snapshot)

}

})

////到上面文件的不同文件

    let databaseRef = Database.database().reference()
let uid = Auth.auth().currentUser!.uid
if Education.text == "" || {
print ("missing")
let alert = UIAlertController(title: "Error", message: "Missing Field.", preferredStyle: UIAlertControllerStyle.alert)
let action = UIAlertAction(title: "Ok", style: .default, handler: nil)
alert.addAction(action)

self.present(alert, animated: true, completion: nil)

}
else if takenImage == nil{

let alert = UIAlertController(title: "Error", message: "Missing Photo.", preferredStyle: UIAlertControllerStyle.alert)
let action = UIAlertAction(title: "Ok", style: .default, handler: nil)
alert.addAction(action)

self.present(alert, animated: true, completion: nil)

}

else {

databaseRef.child("people").child(uid).child("Education").setValue(self.Education.text!)

self.performSegue(withIdentifier: "tohome", sender: nil)

}

最终结果将是除当前显示的用户之外的所有用户。

最佳答案

OP 希望读入存储在/people 节点中的所有用户,但忽略此用户信息。假设正在使用 Firebase 身份验证,并且/people 节点中的每个子节点都具有该用户 uid 的 key 。结构将是

people
uid_0 // firebase uid
name: "Captain Oveur"
email: "oveur@machogrande.com"
uid_1
name: "Mr. Unger"
email: "unger@machogrande.com"
uid_2
name: "Mr. Dunn"
email: "dunn@machogrande.com"

假设 Dunn 先生已登录并且是当前用户。以下代码读入 people 节点中的所有用户并将它们打印到控制台,但忽略当前已通过身份验证的用户信息。

func fetchAllUsersExceptCurrentUser() {
let thisUsersUid = Auth.auth().currentUser?.uid //Mr. Dunn's uid
let usersRef = self.ref.child("users")
usersRef.observeSingleEvent(of: .value, with: { snapshot in
for user in snapshot.children.allObjects as! [DataSnapshot] {
if user.key != thisUsersUid { //do not add this users info to the array
let userObject = user.value as! [String: Any]
let name = userObject["name"] as? String ?? "No name"
let email = userObject["email"] as? String ?? "no email"
print(name, email) //add the data to the array
}
}
})
}

请注意,self.ref 是对我的 Firebase 根节点的引用。你会用你的代替。

关于ios - 我在一个页面上显示所有用户的图片和教育,如何从列表中删除当前用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56733663/

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