【问题标题】:SIGABRT when casting one TableViewController to another将一个 TableViewController 转换为另一个时的 SIGABRT
【发布时间】: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

标签: swift xcode segue sigabrt


【解决方案1】:

正如@Vacawama 所说 - 转到您的故事板并查看您将要使用的 ViewController - 当您的代码中将其列为 AddAccountTVC 时,您将其列为 AccountsTVC

let sourceVC = segue.destination as! AddAccountTVC

所以其中一个是错误的。调整一下就好了

【讨论】:

  • 谢谢。我是新手,所以我很感激耐心啊哈
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-10
  • 2017-05-18
  • 2012-10-27
  • 2011-04-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多