-3

1

I've searched this site and the web and just looking for a simple example on how to reload the root view controller's table view from the detail view. I've tried notifications, setting a tableview in the detailview controller equal to the tableview of the rootview controller...nothing works.

Phil Dukhov
  • 67,741
  • 15
  • 184
  • 220
  • Do you mean that you are working with SplitVC? – Kudos Aug 09 '21 at 06:47
  • 1
    It depends on how the main and detail controllers are related. Please show your code. – vadian Aug 09 '21 at 06:48
  • in first VC class DataManager { static let shared = DataManager() var firstVC = AdminSupportViewController() } – user255112 Aug 09 '21 at 07:05
  • in secondVC DataManager.shared.firstVC.adminTV.reloadData() – user255112 Aug 09 '21 at 07:06
  • `AdminSupportViewController()` creates a brand new instance which is **not** the instance in the storyboard. You need a segue or instantiation from the storyboard. And please don't add information in the comments, **edit** your question. – vadian Aug 09 '21 at 08:15

1 Answers1

-1

You can use Closure Callback or NotificationCenter

By NotificationCenter:

in DetailsViewController

func clickButtonToReloadData(){
    NotificationCenter.default.post(name: Notification.Name("ReloadDataOfTableView"), object: nil, userInfo: [:])
}

in RootViewController:

override func viewDidLoad() {
   super.viewDidLoad() 
   NotificationCenter.default.addObserver(self, selector: #selector(reloadDataOfTableView), name: "ReloadDataOfTableView", object: nil)
}
    
@objc func reloadDataOfTableView(notification : NSNotification){
    self.tableView.reloadData()
}
    
override func viewWillDisappear(_ animated: Bool) {         
    NotificationCenter.default.removeObserver(self, name: "ReloadDataOfTableView", object: nil)   
}