Reputation: 69
I am still trying to make sense of this idea myself so if I am unclear I apologize. If there are more questions please ask instead of down voting.
Im my app I have a tableview populated with restaurant names that I am querying from parse. What I want to do is: when the user clicks on a cell I want to have have the cell segue to a tableView populated with that restaurants menu.
Now, my question is: 1. How can I have the segue identify the parse ID of the restaurant selected at the indexPath and have this ID input into the query for the appropriate menu in the parse database.
Upvotes: 0
Views: 89
Reputation: 1066
When user clicks on a particular row of tableView, didSelectRowAtIndexPath
will be triggered. So, you can get the name of the restaurant user clicked by getting the element at index path. See ex below.
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let index = self.tableView.indexPathForSelectedRow?.row
//assuming listOfRestaurants is your list of restaurants
let restaurantName = listOfRestaurants[index!] as String
//now you can query the database with the restaurantName to get details
//once you get the details Object
performSegueWithIdentifier(segueId!, sender: self)
//here segueId is the name of your segue identifier
}
//later in your prepareForSegue method pass the data you retrieved from database to the new View controller. Ex follows.
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
//considering restaurantDetailsSegue as your segue id
if (segue.identifier == "restaurantDetailsSegue") {
let NVC: newViewController = segue.destinationViewController as! newViewController
NVC.details = details
}
}
Hope it helps.
Upvotes: 0
Reputation: 5248
You can use prepareForSegue
to get a reference to the view controller you're passing the information to, and set that info before you segue to it, so that your new view controller has the appropriate Parse object. As well as a reference to the new view controller, you can also get a reference to the index path that was selected, and use your data source to pass the information along.
Upvotes: 1