I am trying to pass data from my UITableView to a UIViewController to show more detail.
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "PassDetail" {
let vc = segue.destinationViewController as! ToDoListDetailViewController
let customIndexPath = self.tableView.indexPathForSelectedRow
vc.titleString = userList[userList.count - customIndexPath!.row - 1].Title
vc.descriptionString = userList[userList.count - customIndexPath!.row - 1].Description
}
}
I created a segue push depricated
and set the appropriate identifier.
After running, nothing is happening. No crash, I tried setting create print methods and nothing is called when I tap on a cell.
I tried to see if there is a value in my strings to pass with print statements and I did not hear back from my print statements.
Even if there isn't any data, the app should at least crash when I tap on a cell. But it doesn't.
I tried using different segues like show
and stuff but that did not do the trick.
Am I missing something from my code?
SOLUTION
I found the solution.
This is how I understand how this works. The code I have above passes the data, but it does not push to the next viewcontroller.
To solve this problem, I used the didelectRowAtIndexPath method and set my strings.
Below is my full working code.
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
contentTitle = "Some title" //contentTitle is a global variable
tableView.deselectRowAtIndexPath(indexPath, animated: true)
let row = indexPath.row
performSegueWithIdentifier("PassData", sender: row)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "PassData" {
let vc = segue.destinationViewController as! ToDoListDetailViewController
vc.titleString = contentTitle //setting the titleString created from my ToDoListDetailViewController and setting it to contentTitle
}
}