Xcode: Passing Information from UITableViewController to UIViewController

后端 未结 2 1628
耶瑟儿~
耶瑟儿~ 2021-01-28 17:06

I have a UIViewController which should show me DetailInformations depending on what Cell was pressed in the UITableViewController.

For the moment I am passing them throu

2条回答
  •  没有蜡笔的小新
    2021-01-28 17:16

    Try using indexPathForSelectedRow in prepareForSegue as of it looks like that you have created segue from UITableViewCell to the Destination ViewController so that prepareForSegue will call before the didSelectRowAt.

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "show" {
            var ctrl = segue.destination as! DetailViewController
            if let indexPath = self.tableView.indexPathForSelectedRow {
                ctrl.information = _informationList[indexPath.row]
            }
        }
    }
    

提交回复
热议问题