ios - Segue 与 pass 数据工作两次
问题描述
我遇到了一个愚蠢的错误。当我运行应用程序时,我的 segue 工作了两次。我有一个包含很多部分和行的 tableview,当用户单击一行时,我想执行 segue 并以编程方式更改目标视图中的文本视图。当我运行程序并单击 tableview 时,segue 会工作两次。有什么问题?
这是我的segue代码:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("section: \(indexPath.section)")
categoriacliccata = indexPath.section
print("row: \(indexPath.row)")
rowCliccata = indexPath.row
performSegue(withIdentifier: "segue_testo", sender: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if (segue.identifier == "segue_testo") {
let secondVC: TextView_Controller = segue.destination as! TextView_Controller
secondVC.recivedCategoria = categoriacliccata
secondVC.recivedRow = rowCliccata
}
}
解决方案
从 VC 本身而不是从单元中进行转场,因为从单元中运行在 IB 中链接的代码和您在其中编写的代码didSelectRow
推荐阅读
- xcode - Alamofire 用户登录 SwiftUI CoreData
- r - 提高循环性能
- javascript - NodeJS 在目录中查找以 name.* 开头的文件
- image - 关于 DCGAN (Pytorch) 中灰度图像通道大小的问题
- python - Plotly Express 似乎只从动画滑块的第一帧中获取颜色属性
- reactjs - 复选框的计数并取消打包以获取复选框的标签
- input - 将具有两个输入的数值函数映射到一个具有一个输入的函数
- python-3.x - 为什么 Qt 中的字体看起来模糊或像素化?
- javascript - 可读流得到一个 blob
- machine-learning - 逻辑回归可以用于包含列表的变量吗?