ios - 表视图没有快速重新加载
问题描述
我的应用程序中有一个添加收藏按钮功能。当用户将商店添加到他的收藏夹时,它会转到他的个人资料。
现在表格视图可以工作,但是当我点击收藏按钮并导航到配置文件视图控制器时,我没有看到我收藏的商店的新数据。但是当我关闭并打开应用程序时,商店变得可见。
我希望它是一旦用户最喜欢的东西就会立即显示在他的个人资料中
我用过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")
}
}
}
}
}
解决方案
viewDidLoad() 在 UIViewController 创建时只被调用一次。您可以尝试在 viewWillAppear() 方法上调用它
推荐阅读
- selenium - JMeter 中的 WebDriver 采样器中的预期条件接口错误
- java - ByteBuffer 解码时缺少数据为字符串
- c# - Xamarin Forms 更改特定页面上的 NavBar 背景图像
- python-2.7 - 在机器人中找不到名为“Get Child WebElement”的关键字
- c++ - 如何将成员函数指针传递给 libusb?
- java - Hibernate - @MappedSuperclass 中的 @OneToMany 为每个子实体生成表
- tsql - 获取关于非聚合值是否在常量列表中的 BIT 值
- json - 条件空手道 API 测试工具中的模糊匹配
- youtube-api - 在应用程序中使用嵌入式播放器在 Youtube 上直播是否违规?
- javascript - 对于某些用户,React Native Fetch Requests 没有被发送到我的 Node Js 后端