0

I use the storyboard, and the first view is FB login. I want to switch view to the Navigation controller after FB login successfully (FB login can work).

I don't know how to switch the view. I even use a button and push, but it is not working.

The FBloginViewController class:

#import "FBloginViewController.h"
#import <FacebookSDK/FacebookSDK.h>

@interface LoginStatusViewController ()

-(void)toggleHiddenState:(BOOL)shouldHide;

@end

@implementation FBLoginViewController

-(void)toggleHiddenState:(BOOL)shouldHide{
    self.lblUsername.hidden = shouldHide;
    self.lblEmail.hidden = shouldHide;
    self.profilePicture.hidden = shouldHide;
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

-(void)loginView:(FBLoginView *)loginView handleError:(NSError *)error{
    NSLog(@"%@", [error localizedDescription]);
}

-(void)loginViewShowingLoggedOutUser:(FBLoginView *)loginView{
    self.lblLoginStatus.text = @"You are logged out";

    [self toggleHiddenState:YES];
}

-(void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user{
    NSLog(@"%@", user);
    self.profilePicture.profileID = user.objectID;
    self.lblUsername.text = user.name;
    self.lblEmail.text = [user objectForKey:@"email"];
}

-(void)loginViewShowingLoggedInUser:(FBLoginView *)loginView{
    self.lblLoginStatus.text = @"You are logged in.";
    [self toggleHiddenState:NO];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    [self toggleHiddenState:YES];
    self.lblLoginStatus.text = @"";
    self.loginButton.readPermissions = @[@"public_profile", @"email"];
    self.loginButton.delegate = self;

}
Qantas 94 Heavy
  • 15,410
  • 31
  • 63
  • 82
Ken-Zheng
  • 102
  • 3
  • 12
  • try this http://stackoverflow.com/questions/19563158/how-to-fetch-users-email-using-fbloginview/19563502#19563502 – Anbu.Karthik Aug 01 '14 at 06:00
  • if u need any help I hope with u – Anbu.Karthik Aug 01 '14 at 06:02
  • The FB login can work, but I don't know how to switch view to the Navigation controller. – Ken-Zheng Aug 01 '14 at 06:13
  • r u using xib or storyboard bro – Anbu.Karthik Aug 01 '14 at 06:13
  • if u are using xib use this : http://stackoverflow.com/questions/20742745/navigation-controller-push-view-controller/20742996#20742996 other wise if u r using storyboard use this : http://stackoverflow.com/questions/20715462/receiver-viewcontroller-has-no-segue-with-identifier-addsegue/20715545#20715545 – Anbu.Karthik Aug 01 '14 at 06:15

3 Answers3

1

It seems you have to look into how to set up properly the view controllers in the application.

From th question the structure is

App Launch -> FBLogin -> NAv Contoller -> Next Viewcontroller

Change this to

App Launch ->NAv Contoller-> FBLogin ->(PUSH)-> Next Viewcontroller

Means embed the navigation controller in the FBLogin VC and continue the workflow

use method -pushViewController:animated: to move to next page

Lithu T.V
  • 19,707
  • 11
  • 54
  • 98
  • Can you give me a sample code or method? Because I don't know how to auto push after FB login successfully... Thank you very much! – Ken-Zheng Aug 01 '14 at 06:24
1

Use this method in your code at the point wherever you want to perform a switch forward to a new Controller.

[self performSegueWithIdentifier:@"yourSegueIdentifierName" sender:nil];

You will have to connect a segue in the Interface Builder or provide a segue programatically in your application.This method will automatically trigger the prepareForSegue method as soon as the above statement is encountered and the next controller will appear.

Hope this helps.

Matt Murdock
  • 3,203
  • 6
  • 20
  • 34
0

Replace your methods with this:

-(void)loginViewShowingLoggedInUser:(FBLoginView *)loginView{
   self.lblLoginStatus.text = @"You are logged in.";
   [self toggleHiddenState:NO];
   //if you have anavigation controller then
   [self performSegueWithIdentifier:@"yourSegueIdentifierName" sender:nil];
   //if you want to open a modal viewController
   YOURVIEWCONTROLLER *vc1 = [[YOURVIEWCONTROLLER alloc] initWithNibName:@"YOURVIEWCONTROLLER" bundle:nil];
   [vc1 setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
   [self presentViewController:vc1 animated:YES completion:nil];
}
BHASKAR
  • 1,201
  • 1
  • 9
  • 20