1

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.

RedLineTom
  • 35
  • 10
  • No. My tableview loads properly and I can click on the cell to show the information thats needed but when I click the back button to go back to the tableview it'll start from the very beginning again and not the cell that I clicked on. – RedLineTom Aug 09 '15 at 20:19
  • 1
    What you want is actually the default behaviour. So there must be something in your code which causes this scrolling. Do you have any custom code in `viewWillAppear` or `viewDidAppear`? – Glorfindel Aug 09 '15 at 20:21
  • I don't with my view controller with the tableview code. I'm going to edit my question with what I have for the tableview view controller – RedLineTom Aug 09 '15 at 20:28
  • ^^ The above link is for Objective C. If you want it in Swift and can't translate it yourself, try this: http://stackoverflow.com/a/25080883/2574577 – Max von Hippel Aug 09 '15 at 20:30
  • That seems to be making it scroll to the top though and I'm trying to make it stay where it was. – RedLineTom Aug 09 '15 at 20:41
  • its still not working and going to the top when i hit the back button – RedLineTom Aug 09 '15 at 23:15

0 Answers0