gpt4 book ai didi

swift - 准备Segue : one VC to another VC with optionals?

转载 作者:行者123 更新时间:2023-11-30 10:33:25 25 4
gpt4 key购买 nike

我有一个变量 usernameSelected,我想将其发送给第二个 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]
}
}

最佳答案

选择了:

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
}
}

关于swift - 准备Segue : one VC to another VC with optionals?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58609647/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com