简体   繁体   中英

IOS switch view after FB login

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;

}

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

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.

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];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM