gpt4 book ai didi

ios - 通过发件人将 indexPath.row 从 didselectRowAtIndexPath 发送到 prepareForSegue

转载 作者:搜寻专家 更新时间:2023-11-01 07:27:17 24 4
gpt4 key购买 nike

我见过很多解决方案,但我做不到。我想在点击单元格时从 didSelectRowAtIndexPath 函数调用 prepareForSegue 。然后我想从 prepareForSegue 函数内部检索被点击的行索引,这样我就可以使用它来将信息传递给另一个 View 。我认为我正确地调用了该函数,但是我的 prepareForSegue 函数出了点问题。我知道这是一个简单的解决方案,我只是很困惑。这是我当前的代码

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
performSegueWithIdentifier("notificationsToAnswers", sender: self)
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
//the below line is incorrect and should be something else
let selectedIndex = tableView.indexPathForSelectedRow?.row
//pass data on using the index
}

最佳答案

你应该这样通过:

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
performSegueWithIdentifier("notificationsToAnswers", sender: indexPath)
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "notificationsToAnswers" {
//the below line is incorrect and should be something else
let selectedIndexPath = sender as! NSIndexPath
let index = selectedIndexPath.row
//pass data on using the index
}

}

关于ios - 通过发件人将 indexPath.row 从 didselectRowAtIndexPath 发送到 prepareForSegue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35171259/

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