gpt4 book ai didi

ios - 取消关注用户后 TableView 不重新加载数据 swift

转载 作者:行者123 更新时间:2023-11-29 05:44:15 31 4
gpt4 key购买 nike

当我关注用户时,我正在使用 firebase,他的帖子很好地显示在 UITableView 中。但是当取消关注他时,他的帖子仍然在 UITableView 中。 UITableView 取消关注后不重新加载数据。

View Controller :

import UIKit
import SVProgressHUD
import SDWebImage
class HomeVC: UIViewController {

@IBOutlet weak var tableViewOutLet: UITableView!

@IBOutlet weak var activityIndicatorView: UIActivityIndicatorView!
var postContentArray = [Post]() // contine all Posts .
var userContentArray = [UserModel]()

override func viewDidLoad() {
super.viewDidLoad()
tableViewOutLet.dataSource = self
tableViewOutLet.estimatedRowHeight = 521
tableViewOutLet.rowHeight = UITableView.automaticDimension
loadPosts()

}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.tabBarController?.tabBar.isHidden = false
}


@objc func loadPosts () {
// activityIndicatorView.startAnimating()
API.Feed.ObserveFeedWithMyPostAndFollowerPost(withid: API.User.Curren_User!.uid) { (postr) in

self.fetchUserInfo(PostUserID: postr.userPostId!, Completed: {
self.postContentArray.append(postr)
// self.activityIndicatorView.stopAnimating()
self.tableViewOutLet.reloadData()

})
}

API.Feed.ObserveFeedReomved(withid: API.User.Curren_User!.uid) { (key) in
// print(key)

self.postContentArray = self.postContentArray.filter {$0.userPostId != key }
self.tableViewOutLet.reloadData()
}
}




@objc func fetchUserInfo (PostUserID : String , Completed : @escaping ()-> Void) {

API.User.observeUserInformation(CommentUserID: PostUserID) { (User) in
self.userContentArray.append(User)
Completed()
}
}

@IBAction func logOutButton(_ sender: Any) {

AuthServices.logout(OnSuccess: {
SVProgressHUD.showSuccess(withStatus: "تم تسجيل الخروج")
let storyBoard = UIStoryboard(name: "Start", bundle: nil)
let signInvc = storyBoard.instantiateViewController(withIdentifier: "SignInVC")
self.present(signInvc, animated: true, completion: nil)
}) { (error) in
SVProgressHUD.showError(withStatus: error)
}

}


override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "commentIconSequeToCommentPage" {
let commentvc = segue.destination as! CommentsVC
commentvc.postID = sender as? String
}
}
}

extension HomeVC: UITableViewDataSource {


func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return postContentArray.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "PostCell", for: indexPath) as! HomeTableViewCell
let postContent = postContentArray[indexPath.row]
let userContent = userContentArray[indexPath.row]
cell.postContent = postContent
cell.userContentInfo = userContent

cell.homeView = self
return cell
}

}

观察函数:

import Foundation
import FirebaseDatabase
class FeedAPI {
var REF_FEED = Database.database().reference().child("Feed")

func ObserveFeedWithMyPostAndFollowerPost (withid id : String , complation : @escaping (Post)->Void) {
REF_FEED.child(id).observe(DataEventType.childAdded) { (snapshto : DataSnapshot) in
let key = snapshto.key
API.Post.observePostFuntion(withID: key, Complation: { (post) in
complation(post)
})
}
}

func ObserveFeedReomved (withid id : String , complation : @escaping (String)->Void) {
REF_FEED.child(id).observe(DataEventType.childRemoved) { (snapshot : DataSnapshot) in
let key = snapshot.key

complation(key)
}
}
}

最佳答案

取消关注功能到底在哪里?

您还应该设置 tableview delegate

override func viewDidLoad() {
tableViewOutLet.delegate = self
}

请说明您到底在哪里执行取消关注功能。

关于ios - 取消关注用户后 TableView 不重新加载数据 swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56291478/

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