2
votes

I'm struggling the whole day to fix "has no segue with identifier" error and got stuck.

Error message:

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:

Related files getting error:

Please check my Main.storyboard on GitHub.

Xcode project files on Github

Segue diagram

Capture of segue configuration for ViewController (???? Working)

Capture of segue configuration for TableViewController (❌ Getting error)

Environment:

  • macOS Mojave 10.14.2
  • Xcode 10.1
  • Swift 4.2

What I did in Main.storyboard:

  1. Created UINavigationController as an initial view controller and connect to RootViewController as a root view controller

  2. Create UINavigationController that opened from RootViewController as a modal view

  3. Connected the Open Modal button with the modal UINavigationController and named it navigationSegue

  4. Create ViewController, TableViewController, and CollectionViewController

  5. Connect the modal UINavigationController with the ViewController as a root view controller

  6. Connect the ViewController with the TableViewController as a triggered segue (manual) named viewToTableSegue

  7. Connect the TableViewController with the CollectionViewController as a triggered segue (manual) named tableToCollectionSegue

  8. Connect the the Next Button on the ViewController with @IBAction func didTapNext(_ sender: Any) declared in ViewController.swift

How the error occurs:

When I called performSegue(withIdentifier:sender:) in ViewController.swift, it works. (Segue capture)

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

When I called performSegue(withIdentifier:sender:) in TableViewController.swift, it got the error. (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)
}

What I have read:

What I have tried:

  • Make sure the segue identifiers are correctly specified and actually connected
  • Reset all simulator settings and contents
  • Clean Xcode Build Folders and ~/Library/Developer/Xcode/DerivedData/ directory
  • Rename Storyboard
  • Restart and rebuild Xcode project
  • Restart Mac
1
In my case, it is not an unwinding issue, and I've already tried deleting, renaming, and recreating the segue. It did not help.B.Gates Fanboy
I set segue identifier for TableViewController. (Capture Image) Could you answer more concretely?B.Gates Fanboy
Note that we prefer a technical style of writing here. We gently discourage greetings, hope-you-can-helps, thanks, advance thanks, notes of appreciation, regards, kind regards, signatures, please-can-you-helps, chatty material and abbreviated txtspk, pleading, how long you've been stuck, voting advice, meta commentary, etc. Just explain your problem, and show what you've tried, what you expected, and what actually happened.double-beep

1 Answers

0
votes

Remove the following lines from TableViewController:

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