在我的快速应用程序中,我有这个功能,我不会指定类,因为它并不重要。
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”为零。我怎么解决这个问题?
如果你正在使用segues,你应该使用performSegue(withIdentifier:sender:)
你正在使用独立于故事板代表的present(_:animated:completion:)
。