i have a largely populated slide out TableView running in my app over 50+ cell row.When I scroll down to a specific cell and drill down to detailedviewcontrollers and return again the table is scrolled all the way to the top. I've had a look at the following questions that are similar
How can I get the UITableView scroll position so I can save it?
Setting scroll position in UITableView
Remembering scroll position on UITableView
https://grokswift.com/programmatic-uitableview-scrolling/
I tried to workout the solution from the above link and answers but, still i have no luck so far.i am posting my tries as below.
Method 1:
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.myTableView.reloadData()
self.myTableView.setContentOffset(CGPointMake(0, -20), animated: false)
}
Method 2:
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.myTableView.reloadData()
dispatch_async(dispatch_get_main_queue(), {() -> Void in
let rowIndexPath: NSIndexPath = NSIndexPath(forRow: 3, inSection: 0)
self.myTableView.scrollToRowAtIndexPath(rowIndexPath, atScrollPosition: .Middle, animated: false)
})
}
Method 3:
func scrollToSelectedRow() {
let selectedRows = self.tableView.indexPathsForSelectedRows
if let selectedRow:NSIndexPath = selectedRows?[0] {
self.tableView.scrollToRowAtIndexPath(selectedRow, atScrollPosition: .Middle, animated: true)
}
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.myTableView.reloadData()
func scrollToSelectedRow()
}
thanks in Advance...