First, thanks for reading my question!
So, I have been running into some issues regarding getting my cell names to pass onto the next view. Right now it will pass it on but it will only display the most recently loaded cell.
Here is how it is programmed right now:
var passName = ""
var passAuthor = ""
var passLikes = 0
var passDescrip = ""
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
// Configure the PFQueryTableView
self.parseClassName = "Location"
self.textKey = "Name"
self.pullToRefreshEnabled = true
self.paginationEnabled = true
self.objectsPerPage = 5
}
override func queryForTable() -> PFQuery {
let query = PFQuery(className: "Location")
query.orderByAscending("Name")
return query
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> CustomPFTableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell") as! CustomPFTableViewCell!
print("Loading Parse Database Files...")
// Extract values from the PFObject to display in the table cell
if let name = object?["Name"] as? String {
cell?.nameTextLabel?.text = name
passName = name
print("Loading " + name)
}
if let author = object?["authorName"] as? String {
cell?.authorTextLabel?.text = author
passAuthor = author
}
if let likes = object?["Likes"] as? Int {
let stringVal = String(likes)
cell?.numLikes.text = stringVal
passLikes = likes
}
if let descrip = object?["Description"] as? String {
passDescrip = descrip
}
let initialThumbnail = UIImage(named: "Unloaded")
cell.customFlag.image = initialThumbnail
if let thumbnail = object?["imageCover"] as? PFFile {
cell.customFlag.file = thumbnail
cell.customFlag.loadInBackground()
}
print("Finished loading!")
return cell
}
//Original prepareForSegue
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "toDetailScene") {
// initialize new view controller and cast it as your view controller
let viewController = segue.destinationViewController as! DetailViewController
viewController.tripName = passName
viewController.tripAuthor = passAuthor
viewController.tripLikes = passLikes
viewController.tripDescrip = passDescrip
}
}
Later, the next view controller recieves it with this simple code: @IBOutlet weak var name: UILabel! @IBOutlet weak var likes: UILabel! @IBOutlet weak var author: UILabel! @IBOutlet weak var descrip: UITextView!
var currentObject : PFObject?
var tripName = ""
var tripAuthor = ""
var tripLikes = 0
var tripDescrip = ""
override func viewDidLoad() {
super.viewDidLoad()
//Hookup
name.text = tripName
likes.text = String(tripLikes)
author.text = tripAuthor
descrip.text = tripDescrip
}
I need to fix it so that it doesn't awkwardly show the wrong article/info all the time.
If I could simply pull the correct cell that they clicked on then I could pull the text from each label? So how could I go about getting the right cell?
BTW: It is segued to the next view controller just from the cell to the view controller with a show segue. (In a navigation controller)
Thanks so much!
senderinprepareForSegueis the cell that was tapped - Paulw11