Passing data between two UIViewControllers using Swift and Storyboard

前端 未结 2 1811
情书的邮戳
情书的邮戳 2021-01-23 06:08

I was using below code to selected UITableView to pass data between UIViewControllers

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
          


        
2条回答
  •  囚心锁ツ
    2021-01-23 06:34

    This should work:

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "showRecipeDetail" {
    
                var detailsVC = segue.destinationViewController as SecondViewController
                let indexPath = tableView.indexPathForSelectedRow()
                detailsVC.passedString = recipes![indexPath?row]
                //or try that if above doesn't work: detailsVC.passedString = recipes[indexPath?row]
            }
        }
    }
    

    This line could require amendments:

    destViewController?.destViewController.recipeName = recipes![i]
    

    it depends is you properties optional or not (maybe you have to remove ? or !)

提交回复
热议问题