【发布时间】:2018-06-13 16:56:01
【问题描述】:
这是来自 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)
}
}
}
let sourceVC = segue.destination as! AddAccountTVC 行上有一个SIGABRT,表示它
无法转换类型为“Password_Alcatraz_2.AccountsTVC”的值 (0x1019d6468) 到 'Password_Alcatraz_2.AddAccountTVC' (0x1019d61b0)。
这两个是不同的表视图控制器。我是 swift 新手,所以我不明白为什么它不允许我在它们之间传递数据。任何帮助表示赞赏。
【问题讨论】:
-
在 Storyboard 中检查与目标 VC 关联的类。当需要设置为
AddAccountTVC时,显然设置为AccountsTVC。