Reputation: 2855
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).
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
Upvotes: 0
Views: 1739
Reputation: 45490
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];
}
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];
}
Upvotes: 1