2

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

    }

}
Cyril
  • 2,783
  • 1
  • 24
  • 35
  • The first thing you should try and see is, whether "userList[userList.count - customIndexPath!.row - 1].Title" has any value. Put a print statement after you set the vc variables and see what happens. Also make sure your segue identifier is correct – Avinash12388 Jul 23 '16 at 18:57
  • @The_Curry_Man I did that and I did not hear back from my print statement. Even if there isn't a value in my userList, it should at least crash but I it doesn't. – Cyril Jul 23 '16 at 19:00

1 Answers1

1

From what I suspect, you have not programmatically pushed your segue.

Taking hint from here, did you push the segue from your didSelectRowAtIndexPath method?

Community
  • 1
  • 1
NiCk.JaY
  • 141
  • 1
  • 8
  • I originally tried to push the segue, but the proper way is to show the segue. But that did not work either. – Cyril Jul 23 '16 at 19:06
  • That's okay, but did you do it manually from you didSelectRowAtIndexPath method? – NiCk.JaY Jul 23 '16 at 19:09
  • hmm, no I don't have that actually. I'll get back to you when I get the chance go try that – Cyril Jul 23 '16 at 19:59