1

Im in a very deep pickle. I realize there are a good amount of SO topics regarding my error and i'v been through 3-4 pages of Google search results of those answers and have tried all the solutions. None have worked.

What Iv tried :

  1. Reset Simulator Settings
  2. Clean out Xcode Build files
  3. Rename Storyboard
  4. Check to see if segue identified is not spelled wrong (hundreds of times)
  5. Restart and rebuild xCode project
  6. Make sure the segue is actually associated with the ViewController in the error.

Problem : Iv made a segue from ViewProjectViewController to RecordModule. Then I programmatically added a bar button to the NavBar of ViewProjectViewController since that Nav bar is made programmatically from the previous VC.

Then as you can for 'item3'..that is the button I click to run the function with performSegueWithIdentifier. But when I click it I get this error:

2016-04-29 12:54:59.098 music[9298:1272742] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<music.ViewProjectViewController: 0x7bead670>) has no segue with identifier 'recMod''
*** First throw call stack:
(
    0   CoreFoundation                      0x00ac3494 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x02e9be02 objc_exception_throw + 50
    2   UIKit                               0x01b4971c -[UIViewController shouldPerformSegueWithIdentifier:sender:] + 0
    3   music                               0x00089ad8 _TFC5music25ViewProjectViewController13openRecModulefPs9AnyObject_T_ + 168
    4   music                               0x00089b4a _TToFC5music25ViewProjectViewController13openRecModulefPs9AnyObject_T_ + 58
    5   libobjc.A.dylib                     0x02eb00b5 -[NSObject performSelector:withObject:withObject:] + 84
    6   UIKit                               0x01977e38 -[UIApplication sendAction:to:from:forEvent:] + 118
    7   UIKit                               0x01e079da -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 179
    8   libobjc.A.dylib                     0x02eb00b5 -[NSObject performSelector:withObject:withObject:] + 84
    9   UIKit                               0x01977e38 -[UIApplication sendAction:to:from:forEvent:] + 118
    10  UIKit                               0x01977db7 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 64
    11  UIKit                               0x01b1bf3b -[UIControl sendAction:to:forEvent:] + 79
    12  UIKit                               0x01b1c2d4 -[UIControl _sendActionsForEvents:withEvent:] + 433
    13  UIKit                               0x01b1c483 -[UIControl _sendActionsForEvents:withEvent:] + 864
    14  UIKit                               0x01b1b2c1 -[UIControl touchesEnded:withEvent:] + 714
    15  UIKit                               0x019f852e -[UIWindow _sendTouchesForEvent:] + 1095
    16  UIKit                               0x019f95cc -[UIWindow sendEvent:] + 1159
    17  UIKit                               0x0199abe8 -[UIApplication sendEvent:] + 266
    18  UIKit                               0x0196f769 _UIApplicationHandleEventQueue + 7795
    19  CoreFoundation                      0x009d5e5f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    20  CoreFoundation                      0x009cbaeb __CFRunLoopDoSources0 + 523
    21  CoreFoundation                      0x009caf08 __CFRunLoopRun + 1032
    22  CoreFoundation                      0x009ca846 CFRunLoopRunSpecific + 470
    23  CoreFoundation                      0x009ca65b CFRunLoopRunInMode + 123
    24  GraphicsServices                    0x05d4e664 GSEventRunModal + 192
    25  GraphicsServices                    0x05d4e4a1 GSEventRun + 104
    26  UIKit                               0x01975eb9 UIApplicationMain + 160
    27  music                               0x000a7391 main + 145
    28  libdyld.dylib                       0x040a1a25 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Heres my code ( ViewController - Starting Point of the Segue)

class ViewProjectViewController: UITableViewController {




    var selectedProj: Array<String> = []
    var selectedKey: String = ""


    var listItemsTwo = [ListItemTwo]()

    let shareDataTwo = SharedDataTwo.sharedInstance


    override func viewDidLoad() {
        super.viewDidLoad()

        // Setup Left UIBarButton Here
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named:  "BackBtn"), style: .Plain, target: self, action: #selector(ViewProjectViewController.backButtonPressed(_:)))


        // Setup Right UIBarButton Here

        var items : Array<UIBarButtonItem> = []


        let item1 = UIBarButtonItem(image: UIImage(named: "SaveBtn"),style: UIBarButtonItemStyle.Plain, target: self, action: #selector(ViewProjectViewController.saveChanges))

        let item2 = UIBarButtonItem(image: UIImage(named:  "EditBtn"), style: .Plain, target: self, action: #selector(ViewProjectViewController.editProject))


        // SEGUE BUTTON NOT WORKING //////////////////////
        let item3 = UIBarButtonItem(title: "Record", style: .Plain, target: self, action: #selector(ViewProjectViewController.openRecModule))
        item3.tintColor = UIColor.redColor()

        items.append(item1)
        items.append(item2)
        items.append(item3)


        self.navigationItem.setRightBarButtonItems(items, animated: true)




        item1.setTitleTextAttributes([
            NSFontAttributeName: UIFont(name: "Aldrich", size: 12.0)!],
                                           forState: UIControlState.Normal)

Heres the segue code (ViewProjectViewController)

func openRecModule(sender: AnyObject) {
    self.performSegueWithIdentifier("recMod", sender: nil)
}

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

    if let destinationVC = segue.destinationViewController as? RecordModule {
        destinationVC.transitioningDelegate = self
    }



}

Interface Builder Image - https://i.stack.imgur.com/h4cgh.png

How ViewProjectViewController Appeared on Screen

The MainPanelViewController directs the user to ViewProjectViewController.

The MainPanelViewController is a UIViewController with UITableView embeded inside. The code for UITableViewCell is below (which is also the segue to ViewProjectViewController)

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

        let keys = Array(sharedDataThree.c.keys)
        let object = self.sharedDataThree.c[keys[indexPath.row]]

        let newProgramVar = object as! NSArray

        let destinationVC = ViewProjectViewController()

        destinationVC.selectedProj = newProgramVar as! Array<String>
        destinationVC.selectedKey = keys[indexPath.row]

        //performSegueWithIdentifier("viewProject", sender: self)

        var alreadyPushed = false

        if let vc = self.navigationController?.viewControllers {
            for viewController in vc {
                if let viewController = viewController as? ViewProjectViewController {
                    self.navigationController?.popToViewController(viewController, animated: true)
                    print("Push your controller")
                    alreadyPushed = true
                    break
                }
            }
        }
        if alreadyPushed == false {
            self.navigationController?.pushViewController(destinationVC, animated: true)
        }
brkr
  • 1,208
  • 1
  • 12
  • 18
  • Open the storyboard file in a regular text editor and search for "recMod" -- make sure it looks like what you think it should (nested in the right place). If you can't figure it out, I guess you could throw it in a gist and link it here. – Lou Franco Apr 29 '16 at 20:21
  • 1
    Also, how did you get ViewProjectViewController on the screen? Did you segue to it? You loaded it from the storyboard, right? – Lou Franco Apr 29 '16 at 20:22
  • I remember having a weird problem like this. Have you tried `Clean Build Folder`? Command+Option+Shift+K will do so. – James Apr 29 '16 at 20:38
  • You might also try deleting the segue completely and then re-creating it. That has worked for me when things don't work for no apparent reason. – Aaron Rasmussen Apr 29 '16 at 21:05
  • @LouFranco I have updated the question above at the bottom to show how the user gets to ViewProjectViewController. Thanks! – brkr Apr 29 '16 at 21:20
  • @James Iv tried this too mate but thank you! – brkr Apr 29 '16 at 21:20
  • The problem is because you are instantiating the view controller directly (with `let destinationVC = ViewProjectViewController()`) rather than loading it from the storyboard. As a consequence it doesn't know anything about the segues that are defined in the storyboard. – pbasdf Apr 29 '16 at 21:25
  • Give the *view controller* an identifier in the storyboard, and then create it with `instantiateViewControllerWithIdentifier`. – pbasdf Apr 29 '16 at 21:27
  • @pbasdf Ok I think I tried what you suggest.. check this - http://imgur.com/a/KcR2x .. But it seems like when I do that I can no longer passes values to the properties at **destinationController.selectedProj or destinatioNVC.selectedKey** anymore. I have be bale to pass those two values in the segue to ViewProjectViewController – brkr Apr 29 '16 at 22:17
  • Can you post the new code? I think you probably just need to cast the newly-created destinationController correctly (`as! ViewProjectViewController`). – pbasdf Apr 29 '16 at 22:32
  • @pbasdf Your a genius! Thank you mate you saved me from dying over this problem over the whole weekend! Im gonna drink a shot in your username! – brkr Apr 29 '16 at 23:42

2 Answers2

0

Try this:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "recMod" {
        let destinationVC = segue.destinationViewController as? RecordModule 
        destinationVC.transitioningDelegate = self
    }
}
Jitendra
  • 842
  • 1
  • 9
  • 25
  • It really looks like prepareForSegue isn't called yet -- it can't find the segue at all. – Lou Franco Apr 29 '16 at 20:34
  • Thank you @Jitendra I have tried this with the same error! – brkr Apr 29 '16 at 21:20
  • Please debug your code and see where the error is coming exactly. Please share the error description from the log. If you are getting same error as mentioned in the question. Try to remove/delete segue and then add segue again to controller and specify another name for it; change it in the code as well. Then verify if its working or not – Jitendra May 01 '16 at 05:37
0

Your problem is this line:

   let destinationVC = ViewProjectViewController()

You didn't load it from the storyboard. There is nothing in this class that knows that you could also create it from the storyboard, so the segues are not there.

Try something like:

 let sb = UIStoryboard(name: "yoursbname", bundle: NSBundle.mainBundle())
 let destinationVC = instantiateViewControllerWithIdentifier("YourVcID") as? 
Lou Franco
  • 87,846
  • 14
  • 132
  • 192