How do I use prepareForSegue in swift?

后端 未结 3 1021
长发绾君心
长发绾君心 2021-01-18 23:56

I have a ViewController with tableview called BasicPhrasesVC and I want to pass the data in the selected cell to display it on the next ViewController (called BasicPhrasesVC

3条回答
  •  星月不相逢
    2021-01-19 00:26

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        selectedBasicPhrase = basicPhrases[indexPath.row]
        self.performSegueWithIdentifier("BasicPhrasesVC2BasicDisplayVC", sender: selectedBasicPhrase)
    
    }
    
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
            if segue.identifier == "BasicPhrasesVC2BasicDisplayVC" {
                if let nextVC = segue.destinationViewController as? NextViewController {
                    nextVC.selectedBasicPhrase = sender
                }
            }
        }
    

提交回复
热议问题