ReloadData wont works as TableView.Window is nil (UITableViewAlertForLayoutOutsideViewHierarchy)

I have a TabBar controller with 4 tabs, all the controller are embedded in Navigation Controller. On the 4th tab there is ViewControllerA which is push to ViewControllerB using embedded navigation controller. Now ControllerB has tableview which gets updated from async service call made every 5 seconds. I am saving the response in database and reloading tableview. 
when the user go back to ControllerA and come back to ControllerB, at this point i am reloading the tableview in ViewDidLoad from the saved data in database.
Until this point everything works as expected. Tableview is refreshed with new data.

But when i get new data from service and try to reload data at this point my CellForRowAtIndexPath breaks and wont reload the table. While trying to recreate this issue I got this UITableViewAlertForLayoutOutsideViewHierarchy.

After testing this numerous time, i found out that ReloadData is not working as my TableView.Window is nil.
After doing some research i tried the suggested solution like reloading data in ViewDidAppear, wrapping up ReloadDate in DispatchQueue.Main, LayoutIfNeeded but nothing seems to work.

I don't know how the tableview is removed from view hierarchy after the reload data is called from ViewDidLoad. 
Tableview is still visible but it just wont refresh anymore. But now if I going back to ControllerA and coming back to ControllerB, it will reload the tableview as latest data in fetched from database but again trying to update from server response will create the same issue.

Not sure how TableView.Window becomes nil.

The fact that the tableView is displayed does not mean your controller has kept a pointer to it.

Could you show code of ControllerB (which holds the tableview) ? And everyplace where you reference tableView in this class.
It sounds like you’re holding on to a reference you shouldn’t be.

window will be nil if the view of the view controller is not in the view hierarchy. So that can mean you’re making the tableview try to layout either before it’s actually been pushed, or after it’s been popped.

ViewControllerB is likely getting deallocated when it moves off screen. Then when you push ViewControllerB it is a new instance, and your service that updates the table view is likely trying to reference the old View Controller. Your data source probably shouldn’t know anything about the view controllers. If your service doesn’t reference the view controller directly then you may have a retain cycle in the methods that you’re observing the updates.
After doing endless testing, I finally figured it out that API calls being made during view controller life cycle was causing the issue. So I removed the calls while ViewController is being loaded. Now ReloadData works fine.

But actually i need those calls to fire every 5 seconds. So i cant actually remove them.
Does anyone have any idea, why it does that.
I need a workaround to stop Tableview.Window being nil in this situation.
If you use core data as Database, you can create a separate class with NSFetchResultController that will handle data updates. Then in ViewControllerB you will subscribe to FetchResult notifications and reload data when it available.
I am using SQLite, and the issue is not with database.
When ever a user go to ControllerB a timer is trigged, firing Get call every 5 sec (it keeps firing even when user go out of the screen). If there is new data available, then i save the response in database and reload the TableView (only when the user is on controllerB), and also fire local notification to alert the user that new data is available.

But issue is when i got back to ControllerA and come back to ControllerB and if the service call are still being made.
Need a work around to stop service call while ControllerB is being loaded.
ReloadData wont works as TableView.Window is nil (UITableViewAlertForLayoutOutsideViewHierarchy)
 
 
Q