仅当在tableView(_:didSelectRowAt :)上调用performSegue时,才会发生“没有标识符的segue”错误

时间:2019-01-10 06:55:17

标签: swift xcode storyboard segue xcode10.1

我整天都在努力解决“没有标识符的问题”错误并陷入困境。

错误消息:

SegueTest[41862:1585831] *** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'Receiver (<SegueTest.TableViewController: 0x7feed6510260>) has no segue with identifier 'tableToCollectionSegue''
*** First throw call stack:

相关文件出错:

请在GitHub上检查我的Main.storyboard

Xcode project files on Github

Segue diagram

Capture of segue configuration for ViewController ( Working)

Capture of segue configuration for TableViewController (❌ Getting error)

环境:

  • macOS Mojave 10.14.2
  • Xcode 10.1
  • 迅速4.2

我在Main.storyboard中所做的事情:

  1. 创建了UINavigationController作为初始视图控制器,并连接到RootViewController作为根视图控制器

  2. 创建从UINavigationController打开的RootViewController作为模态视图

  3. Open Modal按钮与模式UINavigationController连接起来并命名为navigationSegue

  4. 创建ViewControllerTableViewControllerCollectionViewController

  5. 将模式UINavigationControllerViewController作为根视图控制器进行连接

  6. ViewControllerTableViewController连接起来,作为名为viewToTableSegue的触发segue(手动)

  7. TableViewControllerCollectionViewController连接起来,作为名为tableToCollectionSegue的触发segue(手动)

  8. Next上的ViewController按钮与@IBAction func didTapNext(_ sender: Any)中声明的ViewController.swift连接起来

错误发生的方式:

当我在ViewController.swift中呼叫performSegue(withIdentifier:sender:)时,它可以工作。 (Segue capture

// Go to TableViewController
@IBAction func didTapNext(_ sender: Any) {
    //  Working
    self.performSegue(withIdentifier: "viewToTableSegue", sender: nil)
}

当我在TableViewController.swift中调用performSegue(withIdentifier:sender:)时,出现了错误。 (Segue capture

override func tableView(_ tableView: UITableView, 
                        didSelectRowAt indexPath: IndexPath) {
    self.tableView.deselectRow(at: indexPath, animated: true)

    // ❌ The segue `tableToCollectionSegue` is connected
    //    from `TableViewController` to `UICollectionViewController`,
    //    but got error.
    //
    // *** Terminating app due to uncaught exception 'NSInvalidArgumentException',
    // reason: 'Receiver (<SegueTest.TableViewController: 0x7feeea04a090>) has no segue with identifier 'tableToCollectionSegue''

    self.performSegue(withIdentifier: "tableToCollectionSegue", sender: nil)

    // ❌ The segue `tableToCollectionSegue` is not connected
    //    from `UINavigationController` to `UICollectionViewController`.
    //    This error is expected.
    //
    // *** Terminating app due to uncaught exception 'NSInvalidArgumentException',
    // reason: 'Receiver (<SegueTest.TableViewController: 0x7feeea04a090>) has no segue with identifier 'tableToCollectionSegue''

    // self.navigationController?.performSegue(withIdentifier: "tableToCollectionSegue", sender: self)
}

我已阅读的内容:

我尝试过的事情:

  • 确保正确指定了segue标识符并已将其连接
  • 重置所有模拟器设置和内容
  • 清理Xcode构建文件夹和~/Library/Developer/Xcode/DerivedData/目录
  • 重命名情节提要
  • 重新启动并重建Xcode项目
  • 重新启动Mac

1 个答案:

答案 0 :(得分:0)

TableViewController中删除以下几行:

required public init?(coder aDecoder: NSCoder) {
    super.init(style: .plain)
}