i have a tabBar Controller, in segmented 0 i have a viewcontroller that has another view conttroller that also have a a tableview. i have to change from viewcontroller in segmentedIndex 1 when taping in a cell change to selecteIndex 0 like this
let appDelgate = UIApplication.shared.delegate as! AppDelegate
// FIXME: - Update to real post id comming from Notification endpoint
appDelgate.postID = 81
self.tabBarController?.selectedIndex = 0
81 is just for testing purpose then in view controller that manage the selectedIndex 0 i have eset this in viewDidAppear
override func viewDidAppear(_ animated: Bool){
let appDelegate = UIApplication.shared.delegate as! AppDelegate
if let postID = appDelegate.postID, let data = feedFriends.feedVC.theData {
self.pagerVC.selectedIndex = 0
let i = data.index(where: { data in
data.id == postID
})
print("i value: \(i)")
let indexPath = IndexPath.init(row: i!, section: 0)
feedFriends.feedVC.tableView.scrollToRow(at: indexPath , at: .top, animated: true)
appDelegate.postID = nil
print("el valor de post id \(String(describing: appDelegate.postID))")
}
}
all this work as expected if this view have appear before make the transistion in the previos code. is i tap in the selected index 1 and tap a cell to show selectedIndex 0 and this is not be show, then the scroll did not happen do to let data = feedFriends.feedVC.theData
in case this check is not done the i have a unespectely found nil because the theData is not loaded from network due to async task, so how do i do when the data has finished loaded to make the scroll to the desired index.
i have seen this Auto scrolling to a cell with a specific value
but I have solve the problem of scrolling to the specified value. so My question is how to know when to scrool after the tableview has loaded the data, beacuse the tableview does not have a delegate to inform that all data have been loaded so the tableview is goin to reload data, the diferences with the link is that i make the scroll to the desired cell when the tableview alredy have data, but if the all view is not been loaden from story board.
what function or protocol or delegate use to say the tableview hey ahve you loaded your data, then tableview.scrolltorow().