Passing data between two UIViewControllers using Swift and Storyboard

前端 未结 2 1816
情书的邮戳
情书的邮戳 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:33

    Try this... If you're first view controller is embedded inside Navigation Controller, you can push the second view controller on didSelectRowAtINdexPath delegate, as below...

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        // Create a storyboard instance.....
        var storyBoard = UIStoryboard(name: "Main", bundle: nil)
        // Create a SecondViewController instance, from the storyboardID of the same.
        var seconVC = storyBoard.instantiateViewControllerWithIdentifier("seconViewControllerID") as SecondViewController
        seconVC.passedString = receipes[indexPath.row] as String
        self.navigationController?.pushViewController(secondVC, animated: true)
    }
    

提交回复
热议问题