Hello! I try to implement a transition with the transfer of a variable to the ViewController when I click on a table cell, but when I click it, it goes without transferring the value of the table, and then the transition is transferred from the variable already transferred. Those. An extra link appears in the navigation. Here I pass the variable:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { let controller = segue.destinationViewController as! DetailTaskViewController controller.taskID = self.IDForDT override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { let indexPath = tableView.indexPathForSelectedRow! let currentCell = tableView.cellForRowAtIndexPath(indexPath)! as! TaskListTableViewCell self.IDForDT = currentCell.TaskListID.text performSegueWithIdentifier("SHOWDT", sender: self) } 

Here this variable is processed:

 class DetailTaskViewController: UIViewController { var detailtask = [DetailTask?]() var taskID: String? @IBOutlet weak var DetailTaskName: UILabel! @IBOutlet weak var DetailTaskImage: UIImageView! @IBOutlet weak var DetailTaskDescr: UILabel! @IBOutlet weak var DetailTaskURL: UILabel! override func viewDidLoad() { loadTaskList(self.taskID) super.viewDidLoad() print(self.taskID) } //... 

print (self.taskID) first returns nil, and after the already transferred data. Please tell me how can I fix this?

  • In your storyboard segue leads from cell to DetailTaskViewController? So he works out passing nil. Following your program is already triggered. - iosp
  • But how can this be fixed? - M.Sol
  • one
    shouldPerformSegueWithIdentifier - here you check for the presence of the necessary parameters. If there is, allow the transition. - iosp

1 answer 1

The first transition causes a segue coming from the table cell. You call the second transition with the performSegueWithIdentifier command. Remove the storyboard segue coming from the table cell and add a new one (with the same name "SHOWDT") from the uiviewcontroller itself. To add, select the display scale, for example 50% and drag the segue from one uiviewcontroller to the second. This will create a segue that is not tied to a specific element that you invoke through the performSegueWithIdentifier ("SHOWDT", sender: self) command.