I have implemented didSelectRowAtIndexPath in a UITableViewController:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
// determine selected cell
let name = self.names[indexPath.row]
// present menu VC
let destVC: UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("MenuItemsReadOnly") as UIViewController
self.navigationController?.pushViewController(destVC, animated: true)
}
So far so good. It works fine. My problem starts right after I dismiss the destVC:
func doneSelf() {
self.navigationController?.popViewControllerAnimated(true)
}
Following dismissal, I am back to my UITableViewController, but the view scrolls all the way up to the top so that the 1st cell is visible.
I have not implemented function viewDidAppear. I am not calling tableView.reloadData() in viewDidLoad, and this is the only view-related method I have implemented in my UITableViewController:
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.delegate = self
self.tableView.dataSource = self
// format navigation controller
self.navigationController!.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName : UIColor.whiteColor()]
self.navigationController!.navigationBar.translucent = false
self.navigationController!.navigationBar.barStyle = .Black
self.navigationController!.navigationBar.barTintColor = UIColor.flatRedColor()
self.navigationController!.navigationBar.tintColor = UIColor.flatRedColor()
self.automaticallyAdjustsScrollViewInsets = false
self.tableView.backgroundColor = UIColor.flatWhiteColor()
// format table UI
self.tableView.separatorStyle = UITableViewCellSeparatorStyle.None
// last cell would get cropped off without this
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 64, 0)
// navigation buttons
navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "IconMenuShortcut"), style: .Plain, target: self, action: "presentLeftMenuViewController")
navigationItem.leftBarButtonItem?.tintColor = UIColor.whiteColor()
}
Is this by design? How can I keep the selected cell into view once I am back from the 2nd UIViewController and not automatically move back to the top?