1

I have a TableViewConroller embedded in a NavigationController which is has a relationship segue of view controllers. That part works great. What doesn't work is the

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    print("refresh")
    tableView.reloadData()
}

It only fires when the tab is first pressed. I have tried a few suggestions and nothing will refresh the table. Including:

class TabBarControllerViewController: UITabBarController, UITabBarControllerDelegate  {
    override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
        print("Selected item")
        print(item.tag)
        if item.tag == 3 {
            DispatchQueue.main.async(execute: {AlertsTableViewController().buttonMethod()})
        }
    }

Any suggestions?

Storyboard

This is what I found, but isn't working: How to refresh a tableView on click tabBar item Swift?

Community
  • 1
  • 1
Jay
  • 162
  • 1
  • 1
  • 9
  • You have this code in two different classes? – Tushar Sharma Mar 12 '17 at 18:42
  • Yes, the viewWillAppear is in its UITableViewConroller – Jay Mar 12 '17 at 18:44
  • so it is like you want to click on last tab and go on first tab and reload your table? – Tushar Sharma Mar 12 '17 at 18:48
  • I just want to pull new data from a web request and re-populate the table with that data. When you click the refresh button that I have in the TableViewController (visible in the screenshot that I posted) buttonMethod() it works. I just want that code to run when someone presses the tab name for this TableViewController. I can get the code to run via the didSelect function, but it does not update the table, even though it fires. – Jay Mar 12 '17 at 18:54
  • What is `buttonMethod()` doing? Is it starting a web request to fetch new data? Is that request finishing, and you have new data, and the tableview reloads, but the new data is not being used? Or is the tableview *not* reloading (number of section, number of items in section, cell for row, etc not being called)? – DonMag Mar 12 '17 at 23:18

0 Answers0