UITableView scroll to where user clicked
I am sure this a pretty common problem: I have a UITableView with quite some entries in it. If you click on a cell, you get to see some details about the selected object (done with a navigation controller). Now if the user hits the back arrow at the top of the screen, he successfully returns to the old table, but this is now scrolled all the was back to the top, no matter which cell the user touched before.
I create the table in my "viewWillAppear" method of the ViewController. Yet I think this is not my issue, as lo开发者_高级运维g entries have shown that the "reloadData" call (which is in this method) does not get called when I return from another view (hit the back button).
Does anybody know how I can prevent the UITableview from scrolling up when returning from a deeper level?
Thanks a lot!
You should create the table view in -[viewDidLoad]. This will most likely not only solve your problem, but is also a cleaner way to do something like this.
Currently, the table view is newly created every time the view appears, which of course also happens when you return to it by using the back button.
One way is you can record the indexpath that the cell was in, then use UITableView scrolLToRowAtIndexPath to scroll to the cell that was selected, heres a ref http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UITableView_Class/Reference/Reference.html#//apple_ref/occ/instm/UITableView/scrollToRowAtIndexPath:atScrollPosition:animated:
精彩评论