准备功能不会被segue调用

问题描述 投票:0回答:1

在我的快速应用程序中,我有这个功能,我不会指定类,因为它并不重要。

class ViewController: UIViewController {

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if let destination = segue.destination as? LocalTVC,
            let indexPath = tableView.indexPathForSelectedRow {
            destination.selectedLocal = favouriteLocals[indexPath.row]
        }
    }

    func presentLocalTVC() {
        let storyBoard: UIStoryboard = UIStoryboard(name: "Home", bundle: nil)
        let newViewController = storyBoard.instantiateViewController(withIdentifier: "localTVCID") as! LocalTVC
        self.present(newViewController, animated: true, completion: nil)
    }

}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    self.presentLocalTVC()
}

但是当tableViewControlller,LocalTVC出现时,变量“selectedLocal”为零。我怎么解决这个问题?

swift uitableview uistoryboardsegue
1个回答
0
投票

如果你正在使用segues,你应该使用performSegue(withIdentifier:sender:) 你正在使用独立于故事板代表的present(_:animated:completion:)

© www.soinside.com 2019 - 2024. All rights reserved.