iosswiftseguetarget-action

performSegue being called but not actually segueing to VC2? (Swift 3.0)


Can anyone spot my error? The left bar button works to dismiss, however the action button calls performSegue but the UI doesn't change the VC? Calling showLinkPreviewController inside ViewDidLoad works, so apparently it's a problem with the target/action? A bug?

     let button = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(dismissTimeline))
            timelineViewController.navigationItem.leftBarButtonItem = button

            let previewButton = UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(showLinkPreviewViewController))
            timelineViewController.navigationItem.rightBarButtonItem = previewButton

            // Create a navigation controller to hold the
            let navigationController = UINavigationController(rootViewController: timelineViewController)
            showDetailViewController(navigationController, sender: self)
        }
        func dismissTimeline() {
            dismiss(animated: true, completion: nil)
        }

        func showLinkPreviewViewController() {
            self.performSegue(withIdentifier: "showLinkPreviewViewController", sender: self)
        }

  // Create a navigation controller to hold the
        let navigationController = UINavigationController(rootViewController: timelineViewController)
        showDetailViewController(navigationController, sender: self)

Solution

  • Figured it out, the segue was being performed but since I wasn't dismissing my current VC off the stack I couldn't see it:

    The fix:

      func showLinkPreviewViewController() {
            dismiss(animated: true, completion: nil)
            self.performSegue(withIdentifier: "showLinkPreviewViewController", sender: self)
        }