Calling reload Sections from AppDelegate

后端 未结 2 499
我寻月下人不归
我寻月下人不归 2021-01-27 11:29

I am building an app to track BLE devices, and I have a delegate (in appDelegate) that updates the list of discovered devices over the bluetooth.

I need to display this

相关标签:
2条回答
  • 2021-01-27 12:14

    The problem is that ViewController() is not your view controller. It is a new separate instance. You need to refer to your existing view controller.

    0 讨论(0)
  • 2021-01-27 12:22

    So, as @matt pointed out, the problem was that I was instantiating a new ViewController in AppDelegate, so to solve this I did:

    let navController       = self.window?.rootViewController as! UINavigationController
    
    newViewController       = navController.visibleViewController as! ViewController
    

    to, as I understand it, pull the reference to the existing ViewController from the navigation controller.

    Then refering to

    newViewController.refresh()
    

    correctly updates the tableView.

    I welcome any corrections to improve this, but for now my code is working! thanks for the help everyone.

    0 讨论(0)
提交回复
热议问题