首页 > 解决方案 > 表视图没有快速重新加载

问题描述

我的应用程序中有一个添加收藏按钮功能。当用户将商店添加到他的收藏夹时,它会转到他的个人资料。

现在表格视图可以工作,但是当我点击收藏按钮并导航到配置文件视图控制器时,我没有看到我收藏的商店的新数据。但是当我关闭并打开应用程序时,商店变得可见。

我希望它是一旦用户最喜欢的东西就会立即显示在他的个人资料中

我用过tableView.reloadData(),但它不工作。我究竟做错了什么?

这是我的代码:

  func loadData(){// i call thiss function later in the viewDidLoad()
       let userID = Auth.auth().currentUser!.uid

    
    db.collection("Favorites").whereField("usersID", isEqualTo: userID).getDocuments(){
           querySnapshot, error in
           if let error = error {
               print(error.localizedDescription)
           }else
           {
            if(querySnapshot!.isEmpty){
                //here put you didn't favorite any shops image/text
                
            }else{
               self.shops = querySnapshot!.documents.compactMap({addShop(dictionary: $0.data())})
               DispatchQueue.main.async {
                
                self.faveList.reloadData()
                print("reloaded")
                
               }
        }
           }
       }
    
   }

标签: iosswiftuitableview

解决方案


viewDidLoad() 在 UIViewController 创建时只被调用一次。您可以尝试在 viewWillAppear() 方法上调用它


推荐阅读