13

I have problem I've been sitting with. I have a UIViewController List and a UIViewController Login. On Login I have a button "Done", also another hidden button on the same UIViewController that has a segue to List (Type: push). I gave it an identifier in the interface builder of xcode named "LoginToList". Now from another class (a class that runs while Login is the active controller) I call:

[[Login sharedLogin] performSegueWithIdentifier:@"LoginToList"];

The Login class clearly has a segue with identifier "LoginToList"

Yet I keep getting:

 'NSInvalidArgumentException', reason: 'Receiver (<Login: 0x6d79d90>) has no segue with identifier 'LoginToList''

the + (id) sharedLogin looks like this:

+ (id) sharedLogin {
    static Login *sharedLogin = nil;

    @synchronized(self) {
        if (sharedLogin == nil) {
            sharedLogin = [[self alloc] init];
        }

        return sharedLogin;
    }
}

If anyone has any idea why it says that, I'd be glad to hear it! :D I don't know if I'm missing something stupid but I can't spot it :(

EDIT: I have create a segue in the interfacebuilder (ctrl + click drag from Login to List) using the UIViewControllers themselfves (Login & List). Then I named the segue "LoginToList" in other words I gave it that identifier. I clicked the segue and at the top-right there was a "Identifier" field which I used.

I Still get the error saying Login has no segue with identifier "LoginToList". sad

Simon Barkhuizen
  • 846
  • 1
  • 9
  • 18

4 Answers4

2

As far as your code snippet goes, it looks like you tried to create a singleton out of the Login Controller, but only did it half way.

The seque can't be found because the the Controller was initialized using the storyboard, not using your shared class method. So you end up having two independent instances. Additionally, your class method does not initialize the controller with the storyboard bindings, so you don't have any seques here.

You should try to hand a reference of the LoginController's instance (initialized unsing storyboard segues etc.) to the 'other class' and use that one.

  • 2
    Manually created viewControllers as in not loaded from the NIB cannot connect to NIB resources. It is not possible to reuse view controllers outside or inside the context of a storyboard. This is a point of confusion, The one and only viewController you load from a storyboard is connected to its one and only view. Cant be reused, cant be shared. – deleted_user Sep 18 '12 at 05:57
  • I've got a similar problem to this. I've using a Methode which is started "dispatch_async" from there I try to use my UI like that: "ivo_login_ViewController *loginViewController=[[ivo_login_ViewController alloc]init]; loginViewController dataProgress:@"Assignments laden" count:count];" but my UI never gets updated, also I can't start a new ViewController like that. What do I need to change that it uses the right NIB Resource? @deleted_user – safari Aug 26 '13 at 09:23
1
sharedLogin = [[self alloc] init];

try this

sharedLogin = [self.storyboard instantiateViewControllerWithIdentifier:@"xxxx"];

you must set IdentifierName in storyboard LoginViewController

JoshL
  • 10,737
  • 11
  • 55
  • 61
0

without knowing about what your init does ...

i found in attempting to dynamically [[alloc] init] a view controller for use like this, i had to call initWithNibName:bundle:, and thus i had to put my view controller in a separate xib class so it didn't get confused in the storyboard and leave warnings about an unreachable scene.

without initWithNibName:bundle:, my guess is that your call to [[alloc] init] in sharedLogin is not properly tying the UIStorybardSegue* that you you have clearly created to the Login view controller in a way that it can be used from the object returned .

(my situation is that i had a popover in iPad and a regular navigation segue in iPhone. for iPhone, i am using the hidden button with segue in iPhone, but it is performing a segue to a scene and view-controller that undoubtedly gets initialized in awakeFromNib: . for iPad, i'm putting into a popover, and the popover isn't connected to anything … and gets initialized with initWithNibName:bundle: to the item that is in a separate .xib file.]

john.k.doe
  • 7,533
  • 2
  • 37
  • 64
-1

first, i believe segues should follow camel case rules. change to...

loginToList

second, disconnect and reconnect your views in ib.

third, clean your project (shift-command-k).

lastly, you should be using something like this method...

 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"loginToList"]) {
        [[segue destinationViewController] setDelegate:self];
    }

}

for your segue. then setup a delegate protocol method to dismiss the view controller.

DoS
  • 1,454
  • 13
  • 18
  • You don't need prepareForSegue, it is not required to perform a segue at all. You only use it if you want to do some setup before the segue fires. – lkraider May 29 '12 at 17:13