0

I'm a noob to iOS dev and I'm trying to implement a simple Facebook Connect, but when the user is logged in I want the app to change view automatically.

In my storyboard I have the FacebookLoginViewController that is embeded inside a NavigationController. Then I've added a segue between FacebookLoginViewController and UploadViewController (where I let the user pick an image and upload it to AWS S3).

enter image description here

I've check the Facebook Sample to inspire me.

The problem I'm facing is with the segue between FacebookLoginViewController and UploadViewController. This Segue has the following identifier: LoginSuccessSegue

In AppDelegate, when a session state change, the following method is called: - (void)sessionStateChanged:(FBSession *)session state:(FBSessionState) state error:(NSError *)error

In this method, when the user is logged in, another method is called: userLoggedIn

Now, what I want to do here is trigger the Segue to perform the push transition between FacebookLoginViewController and UploadViewController. And I have to do it from the AppDelegate because it's here that the session state is checked.

I've tried to instantiate FacebookLoginViewController and call a method I've defined to trigger the segue.

In AppDelegate.m:

// Show the user the logged-in UI
- (void)userLoggedIn
{
    // Switch view to pick image
    FacebookLoginViewController *LoginController = [[FacebookLoginViewController alloc] init];
    [LoginController successLoginTransition];
}

In FacebookLoginViewController.m:

-(void)successLoginTransition
{
    [self performSegueWithIdentifier:@"LoginSuccessSegue" sender:self];
}

But doing so I end up with the following error:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver () has no segue with identifier 'LoginSuccessSegue''


To make sure the Segue is working, I've created a button in the FacebookLoginViewController that is calling the following method:

-(IBAction)testSegue:(id)sender
{
    [self performSegueWithIdentifier:@"LoginSuccessSegue" sender:self];
}

And this is working.


I've tried to search for this error but I could find anything helpful.

Can you please tell me what am I doing wrong and maybe how I should do to trigger this transition?

Cheers, Maxime

maxwell2022
  • 2,818
  • 5
  • 41
  • 60

1 Answers1

1

Don't alloc init the UIViewController because you are using storyboards.

Change

- (void)userLoggedIn
{
    // Switch view to pick image
    FacebookLoginViewController *LoginController =
                                          [[FacebookLoginViewController alloc] init];
    [LoginController successLoginTransition];
}

to

- (void)userLoggedIn
{
    // Switch view to pick image
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" 
                                                         bundle:nil];
    FacebookLoginViewController *LoginController = 
                 [storyboard instantiateViewControllerWithIdentifier:@"FbLoginView"];
    [LoginController successLoginTransition];
}

enter image description here

EDIT:

You want to naviguate to the image Picker, no need to make the LoginController push a segue. you can just do it directly:

- (void)userLoggedIn
{
    // Switch view to pick image
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    pickImageViewController *LoginController = [storyboard instantiateViewControllerWithIdentifier:@"pickImageView"];
    [(UINavigationController*)self.window.rootViewController pushViewController:LoginController animated:NO];
}
meda
  • 45,103
  • 14
  • 92
  • 122
  • it says property storyboard not found – maxwell2022 Apr 16 '14 at 06:32
  • @maxwell2022 oops its different for appdeleguate, I fixed it – meda Apr 16 '14 at 06:35
  • One last question. Where can I find the name of the storyboard? – maxwell2022 Apr 16 '14 at 06:39
  • It looks like mine is called `Main.storyboard` but I got the following error: `Could not find a storyboard named 'Main.storyboard'` – maxwell2022 Apr 16 '14 at 06:42
  • I added an screenshot – meda Apr 16 '14 at 06:44
  • Thanks, now I have the following error: `"Could not load NIB in bundle: 'NSBundle <.../33188979-8D3F-4A0E-8434-59A32B76DE3F/uploadS3.app> (loaded)' with name 'Main_Storyboard'"` – maxwell2022 Apr 16 '14 at 06:48
  • The default name for a storyboard is Main_storyboard - unless you have changed it – Robert J. Clegg Apr 16 '14 at 07:10
  • then it would be `[UIStoryboard storyboardWithName:@"Main" bundle:nil];` – meda Apr 16 '14 at 07:25
  • it was `Main`, I've changed it for `Main_Storyboard`. it was not working so now I've changed it to `Main_iPhone` and still not working. https://github.com/Maxwell2022/S3Upload/blob/master/uploadS3Tutorial/AppDelegate.m#L129 – maxwell2022 Apr 16 '14 at 07:28
  • Thanks for the zip. Changing the storyboard to "Main" fixed it but I have another error: `Could not find a navigation controller for segue 'LoginSuccessSegue'. Push segues can only be used when the source controller is managed by an instance of UINavigationController.` Do I need a second navigation controller in my storyboard? – maxwell2022 Apr 16 '14 at 07:38
  • when do you get this error, when I clicked it took me to the image picker, the other button logged me in an out – meda Apr 16 '14 at 07:41
  • I have an active Facebook session, so the AppDelegate is calling the userLoggedIn method straight when I launch the app in simulator and it crashed at this point – maxwell2022 Apr 16 '14 at 07:45