swift - 将一个 TableViewController 转换为另一个时的 SIGABRT
问题描述
这是来自 Apple 的“人人都能编程”电子书。变量名称已更改以供我个人使用。
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
super.prepare(for: segue, sender: sender)
guard segue.identifier == "saveSegue" else {return}
let website = websiteTextField.text ?? ""
let email = emailTextField.text ?? ""
let username = usernameTextField.text ?? ""
let password = passwordTextField.text ?? ""
account = Account(website: website, username: username, email: email, password: password)
}
这就是segue函数。比较简单
@IBAction func unwindToAccountsPage(segue: UIStoryboardSegue) {
guard segue.identifier == "saveSegue" else {return}
let sourceVC = segue.destination as! AddAccountTVC
if let account = sourceVC.account {
if let selectedIndexPath = tableView.indexPathForSelectedRow {
accounts[selectedIndexPath.row] = account
tableView.reloadRows(at: [selectedIndexPath], with: .none)
} else {
let newIndexPath = IndexPath(row: accounts.count, section: 0)
accounts.append(account)
tableView.insertRows(at: [newIndexPath], with: .automatic)
}
}
}
有一个SIGABRT
就let sourceVC = segue.destination as! AddAccountTVC
行了,说是
无法将“Password_Alcatraz_2.AccountsTVC”(0x1019d6468)类型的值转换为“Password_Alcatraz_2.AddAccountTVC”(0x1019d61b0)。
这两个是不同的表视图控制器。我是 swift 新手,所以我不明白为什么它不允许我在它们之间传递数据。任何帮助表示赞赏。
解决方案
就像@Vacawama 所说的那样-转到您的故事板并查看您要使用的 ViewController-您将其列为 AccountsTVC,而在您的代码中您将其列为 AddAccountTVC
let sourceVC = segue.destination as! AddAccountTVC
所以其中一个是错误的。调整一下就好了
推荐阅读
- laravel - 由于错误的域在wsl2下的docker中运行laravel而得到404
- html - 为什么这个容器会扩展到视口之外?
- linux - 如何在 yotco 中修补 Linux 内核源代码
- python - Flask wtf 表单未提交且无错误反馈
- json - 在Python中将geojson转换为数据框
- sql - 数字表的 SQL CTE 对静态值来说很快,但对表值来说很慢
- openmesh - OpenMesh 跳跃式循环器
- html - 一个TD在手机上消失?
- javascript - 如何判断 Vue 组件是否因热重载而被破坏?
- keras - 在“评估/验证阶段”跳过 Keras 模型中的一些层