Подготовиться к Segue: один венчурный капиталист в другой венчурный капитал с дополнительными? - PullRequest
0 голосов
/ 29 октября 2019

У меня есть одна переменная, usernameSelected, которую я хочу отправить второму VC.

Первый VC:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    tableView.deselectRow(at: indexPath, animated: true)

    let usernameSelectedRow = picUsernameArray[indexPath.row]
    usernameSelected = usernameSelectedRow
    print(usernameSelectedRow)   --> [this prints the right data]
    print(usernameSelected)      --> [this prints the right data]
    performSegue(withIdentifier: "goToProfileSelected", sender: self)

}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "goToProfileSelected" {
        let destination = segue.destination as?
        OtherUserProfileViewController
        print(usernameSelected) ---> [this prints nil!!!!]
        destination!.usernameValue = usernameSelected ---> [this returns nil to second VC]
    }
}

1 Ответ

0 голосов
/ 29 октября 2019

в самом деле выберите:

self.performSegue(withIdentifier: "goToProfileSelected", sender: indexPath) //pass indexPath

сейчас готовится к переходу:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    let index = sender as? IndexPath {
        let name = self.picUsernameArray[index.row]
        destination.usernameValue = name
    } 
}
...