gpt4 book ai didi

ios - 准备 segue 的多个条件不起作用

转载 作者:可可西里 更新时间:2023-11-01 00:36:32 25 4
gpt4 key购买 nike

我正在使用 prepare for segue 在 View Controller 之间发送数据,第一个 if 条件在标识符为“ShowPost”时起作用并将 url 发送到 View Controller 。但是当标识符是“profileInfo”时,segue 不会发送数据。

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "ShowPost" {
if let indexPath = tableView.indexPathForSelectedRow {
let _url = searchResults[indexPath.row]["link"].stringValue
let destinationController = segue.destinationViewController as! ShowPostViewController
destinationController.url = _url
}
else if segue.identifier == "ProfileInfo" {
if let indexPath = tableView.indexPathForSelectedRow {
let _userName = searchResults[indexPath.row]["owner"]["display_name"].stringValue
// print("name dc: \(destinationController.userName)")
let _userId = searchResults[indexPath.row]["owner"]["user_id"].stringValue
let _userReputation = searchResults[indexPath.row]["owner"]["reputation"].stringValue
let _ppImageString = searchResults[indexPath.row]["owner"]["profile_image"].stringValue
let destinationController = segue.destinationViewController as! ProfileInfoViewController
destinationController.userName = _userName
destinationController.userId = _userId
destinationController.userReputation = _userReputation
destinationController.ppImageString = _ppImageString
}
}
}
}

最佳答案

else语句被加在第一个if语句里面,无法运行。

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "ShowPost" {
if let indexPath = tableView.indexPathForSelectedRow {
let _url = searchResults[indexPath.row]["link"].stringValue
let destinationController = segue.destinationViewController as! ShowPostViewController
destinationController.url = _url
}


}
else if segue.identifier == "ProfileInfo" {

if let indexPath = tableView.indexPathForSelectedRow {

let _userName = searchResults[indexPath.row]["owner"]["display_name"].stringValue
// print("name dc: \(destinationController.userName)")
let _userId = searchResults[indexPath.row]["owner"]["user_id"].stringValue
let _userReputation = searchResults[indexPath.row]["owner"]["reputation"].stringValue
let _ppImageString = searchResults[indexPath.row]["owner"]["profile_image"].stringValue
let destinationController = segue.destinationViewController as! ProfileInfoViewController
destinationController.userName = _userName
destinationController.userId = _userId
destinationController.userReputation = _userReputation
destinationController.ppImageString = _ppImageString


}
}

}

关于ios - 准备 segue 的多个条件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37436013/

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