【问题标题】:table view not getting refreshed on opening app打开应用程序时表格视图未刷新
【发布时间】:2016-05-20 23:23:52
【问题描述】:

当应用程序打开或在后台时,我正在使用appdelegate 中的通知来更新消息框表,然后它就可以工作了。

Appdelegate(在 didFinishLaunchingWithOptionsdidReceiveRemoteNotification 中):

NSNotificationCenter.defaultCenter().postNotificationName("changeMessageBox", object: nil)

MessageViewController:

viewdidload:

NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector  (MessagesViewController.reloadtable), name: "changeMessageBox", object: nil)

func reloadtable() 
{
    clearArrays()
    if (PFUser.currentUser()!["firebaseUID"] !== nil)
    {

        self.updateResultArray(PFUser.currentUser()!["firebaseUID"] as! String)

        resultsTable.reloadData()

    }
}

消息框中的数据会刷新。

但是当应用程序关闭并且我收到聊天时,消息框(包含来自所有人而不是个人聊天的消息的窗口)不会更新。

我必须打开应用程序,转到消息框,然后返回主页并再次返回消息框,然后表格视图才会刷新。

你们知道我错过了什么吗?

【问题讨论】:

    标签: ios swift uitableview firebase


    【解决方案1】:

    试试下面的代码发布通知,

    dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), { () -> Void in
    
           NSNotificationCenter.defaultCenter().postNotificationName("changeMessageBox", object: nil)
    
    })
    

    我遇到了同样的问题并像这样解决了。希望这会对你有所帮助。

    【讨论】:

      【解决方案2】:

      当应用处于关闭或挂起状态时接收通知将触发

      application:handleActionWithIdentifier:forRemoteNotification:completionHandler:
      

      尝试使用此方法发布通知。我想它会更新你的观点。

      如果您对通知有疑问,请另外参考此文档

      http://samwize.com/2015/08/07/how-to-handle-remote-notification-with-background-mode-enabled/

      【讨论】:

        猜你喜欢
        • 2018-04-03
        • 1970-01-01
        • 2019-01-19
        • 2013-03-08
        • 1970-01-01
        • 2016-07-18
        • 2011-03-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多