ios - 从 AppDelegate Swift 4 更新 tableView 行
问题描述
[![在此处输入图像描述][1]][1]
你好。我有一个如上图所示的表格视图,并且我收到了一些无声推送通知。根据他们,我需要从tableView
. 因为我现在notification
正在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
填充我的表格视图
解决方案
让应用程序委托广播特定于应用程序的通知中心通知(在主线程上)。让包含您的表格视图的视图控制器侦听该通知并根据需要更新相关单元格。这样您就不会污染您的应用程序委托。应用程序委托应该只处理系统级应用程序的东西,而不是业务逻辑。
推荐阅读
- ios - swift中的UIImage、CIImage和CGImage有什么区别
- oop - 使接口易于正确使用和难以错误使用 - 示例
- java - 内存泄漏 org.jboss.modules.ModuleClassLoader。内存在 java.util.concurrent.ConcurrentHashMap 的一个实例中累积(在 wildfly 上)
- docker - 在 URL http://10.10.10.10/site-a 和 http://10.10.10.10/site-b 的不同子文件夹中托管容器
- r - 通过在 R 中操作数据框将账户级别预测转换为投资组合预测
- spring-boot - Sprinboot 应用程序在 kubernetes 中挂起
- apache-spark - sparklyr spark_apply 很慢
- pandas - Pandas - 将行转换为不同的数据框
- bash - Bash 使用部分符号
- git - 无法将大型仓库从 gitlab 迁移到 github