gpt4 book ai didi

ios - 从 AppDelegate Swift 4 更新 tableView 行

转载 作者:行者123 更新时间:2023-11-30 11:02:44 26 4
gpt4 key购买 nike

[![在此处输入图像描述][1]][1]

你好。我有一个如上图所示的表格 View ,并且我收到了一些无声推送通知。根据它们,我需要从 tableView 重新加载特定单元格。由于我在 AppDelegate 中收到通知,并且此刻我正在重新加载整个 tableView...但我个人不知道没有发现这是最好的解决方案,因为我只需要更新特定行。

有什么提示吗,我如何才能从 appDelegate 更新特定单元格?

if userInfo["notification_type"] as? String == "update_conversation" {
if let rootVC = (self.window?.rootViewController as? UINavigationController)?.visibleViewController {
if rootVC is VoiceViewController {
let chatRoom = rootVC as! VoiceViewController
chatRoom.getConversations()
// the get Conversations method makes a call to api to get some data then I reload the whole tableView
}
}


func getConversations() {
let reachabilityManager = NetworkReachabilityManager()
if (reachabilityManager?.isReachable)! {
ServerConnection.getAllConversation { (data) in
if let _ = data{
self.conversations = data
self.onlineRecent = self.conversations
GlobalMainQueue.async {
self.mainTableView.reloadData()
}
}
}
}
}

这是我的 getConversation 方法,在 VoiceViewController 中使用它来填充我的表格 View

最佳答案

让应用程序委托(delegate)广播特定于应用程序的通知中心通知(在主线程上)。让包含 TableView 的 View Controller 监听该通知并根据需要更新相关单元格。这样您就不会污染您的应用程序委托(delegate)。应用程序委托(delegate)应该只处理系统级应用程序内容,而不是业务逻辑。

关于ios - 从 AppDelegate Swift 4 更新 tableView 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53119375/

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