1

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...

Community
  • 1
  • 1
Joe
  • 8,868
  • 8
  • 37
  • 59
  • 1
    I see you doing some scrolling when the view appears, but I don't see you saving any information about where we were scrolled to when the view disappears. If you don't save state, you can't restore it. – matt Feb 21 '16 at 04:14
  • 1
    Also I would ask whether you are doing "return again" properly. In theory, there should be no information lost while you were out so there should be no need to scroll. I worry that you may in fact be creating a whole new table view, not returning to your old table view at all. – matt Feb 21 '16 at 04:15

0 Answers0