Search code examples
swiftuitableviewuiviewcontrolleruistoryboardsegue

ViewController has no segue, swift


This is a very popular question but with all the two days I have spent hunting a solution, nothing has worked.

I have two TableView Controllers (WeekTableViewController and DiscoverTableViewController) as shown in the picture linked by the segue shown with the name "discoverWorkouts". The DiscoverTableViewController is a subclass of PFQueryTableViewController.

enter image description here

enter image description here

On adding the usual function to segue from the WeekTableViewController to the DiscoverTableViewController, I get the following nasty Error: "WeekTableViewController: 0x1058469c0>) has no segue with identifier 'discoverWorkouts''

I have a button created programatically in the WeekTableViewController and this is my code.

WeekTableViewController :

 override func viewDidLoad() {
        super.viewDidLoad()

        //transitionManager = TransitionManager(transitionAnimation: .Fade)
        //transitioningDelegate = transitionManager


        self.navigationController?.navigationBarHidden = true //Hide the navigation bar
        //        tabBarController?.tabBar.hidden = false
        //        self.hidesBottomBarWhenPushed = true


        //Add a button to the
        pingbutton   = UIButton(type: UIButtonType.Custom) as UIButton
        pingbutton.frame = CGRectMake(328, 620, 30,  30)
        pingbutton.setImage(UIImage(named: "discover"), forState: UIControlState.Normal)
        pingbutton.addTarget(self, action: "pingButtonTapped:", forControlEvents: UIControlEvents.TouchUpInside)
        pingbutton.hidden = true

        self.navigationController?.view.addSubview(ping button)


....

}

//MARK: Button Tapped
    func pingButtonTapped(sender:UIButton!)
    {
        self.performSegueWithIdentifier("discoverWorkouts", sender:self)
    }


    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

if segue.identifier == "openDiscover" {

            let discoveryView = segue.destinationViewController as! DiscoverTableViewController
            discoveryView.transitioningDelegate = self.transitionManager
        }

    }

Putting a break point on the "self.performSegueWithIdentifier("discoverWorkouts", sender:self)" shows that's where the error occurs.

I have tried everything from:

  • Deleting the app on my device and installing it again.
  • Deleting the Segue and adding it again with different names.
  • Rebuilding both tableViewControllers and placing the segue again.

Nothing has worked at all.

Also in my app delegate this is how the WeekTableViewController is launched:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

        UIApplication.sharedApplication().statusBarStyle = .LightContent

        //Launch Process
            let weekView =  WeekTableViewController()
            self.landingNavigationController = UINavigationController(rootViewController: weekView)
            self.landingNavigationController?.navigationBar.barTintColor = UIColor.blackColor()
            self.landingNavigationController?.navigationBarHidden = true

            self.window?.tintColor = UIColor.blackColor() //(red: 0.0, green: 1.0, blue: 30.0/255.0, alpha: 1.0)
            self.window?.rootViewController = self.landingNavigationController
//            self.window?.rootViewController = tabBarNavController
            self.window?.makeKeyAndVisible()


}

Any ideas on what in the world could be happening. Thanks. :)


Solution

  • You have to instantiate your ViewControllers from your storyboard, if you want to use the features of it.

    So instead of creating your ViewControllers yourself, you should do something like this:

    let storyboard = UIStoryboard(name: "MyStoryboardName", bundle: nil)
    self.landingNavigationController = storyboard.instantiateInitialViewController() as! UINavigationController
    // additional setup (optional)
    self.window?.rootViewController = self.landingNavigationController
    self.window?.makeKeyAndVisible()
    

    This will create your initial ViewController (probably a UINavigationController) as it's configured in your storyboard.