I need help with finding a way to have a tableview take off where it was after clicking on a cell. Right now if I scroll down 50 cells click on one than hit the back button to go back to the tableview it starts from the top. I'm looking for when I hit the back button to go back to the tableview for it to be right where I left it. Im programming in swift too.
edit:
import UIKit
import ParseUI
import Parse
import Bolts
class TableViewController: PFQueryTableViewController {
// Initialise the PFQueryTable tableview
override init(style: UITableViewStyle, className: String!) {
super.init(style: style, className: className)
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
// Configure the PFQueryTableView
self.parseClassName = "Products"
self.textKey = "productName"
self.imageKey = "productImage"
self.pullToRefreshEnabled = true
self.paginationEnabled = false
}
// Define the query that will provide the data for the table view
override func queryForTable() -> PFQuery {
var query = PFQuery(className: "Products")
query.orderByDescending("createdAt")
return query
}
//override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("Cell") as! CustomCell!
if cell == nil {
cell = CustomCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Cell")
}
// Extract values from the PFObject to display in the table cell
if let ProductName = object?["ProductName"] as? String {
cell.ProductName.text = ProductName
}
// Display product image
var initialThumbnail = UIImage(named: "question")
cell.ProductImage.image? = initialThumbnail!
if let thumbnail = object?["ProductImage"] as? PFFile {
cell.ProductImage.file = thumbnail
cell.ProductImage.loadInBackground()
}
return cell
}
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using [segue destinationViewController].
var detailScene = segue.destinationViewController as! ProductViewController
// Pass the selected object to the destination view controller.
if let indexPath = self.tableView.indexPathForSelectedRow() {
let row = Int(indexPath.row)
detailScene.currentObject = (objects?[row] as! PFObject)
}
}
}
edit:
I tried the links that were suppose to solve the problem and tried every way to fix it but it still isn't working. After I click on the cell than click the back button to go back to the tableview it starts back at the top of the tableview. instead of where I left off at so I have to scroll all the way down to get back to where I was. Im trying to pretty much save/ remember the cell I clicked on and start from their when I go back to the tableview controller.