2014-02-24 24 views
0

我遵循了git的樞紐Facebook的自定義登錄示範按鈕名稱沒有出現在iOS的

https://github.com/fbsamples/ios-howtos/tree/master/FBLoginCustomUISample

以下的Facebook定製登錄樣本,他們使用的廈門國際銀行,而不是,我是用故事板。

每件事情都很完美,但按鈕名稱沒有出現。

如果有人知道解決方案來解決這個問題,請幫助我 在此先感謝。

我的代碼:

AppDelegate.M

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    ViewController *ViewObj = [[ViewController alloc]init]; 

    self.ViewObj = ViewObj; 

    // Override point for customization after application launch. 
    if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded) { 
     NSLog(@"Found a cached session"); 
     // If there's one, just open the session silently, without showing the user the login UI 
     [FBSession openActiveSessionWithReadPermissions:@[@"basic_info"] 
              allowLoginUI:NO 
             completionHandler:^(FBSession *session, FBSessionState state, NSError *error) { 
              // Handler for session state changes 
              // This method will be called EACH time the session state changes, 
              // also for intermediate states and NOT just when the session open 
              [self sessionStateChanged:session state:state error:error]; 
             }]; 

     // If there's no cached session, we will show a login button 
    } else { 
     UIButton *loginButton = [self.ViewObj btn_LoginAction]; 
     //[loginButton setTitle:@"Log in with Facebook" forState:UIControlStateNormal]; 
     [loginButton setImage:[UIImage imageNamed:@"login_FB.png"] forState:UIControlStateNormal]; 
    } 


    return YES; 
} 

- (void)userLoggedOut 
{ 
    // Set the button title as "Log in with Facebook" 
    UIButton *loginButton = [self.ViewObj btn_LoginAction]; 
    // [loginButton setTitle:@"Log in with Facebook" forState:UIControlStateNormal]; 
    [loginButton setImage:[UIImage imageNamed:@"login_FB.png"] forState:UIControlStateNormal]; 
    // Confirm logout message 
    [self showMessage:@"You're now logged out" withTitle:@""]; 
} 

// Show the user the logged-in UI 
- (void)userLoggedIn 
{ 
    // Set the button title as "Log out" 
    UIButton *loginButton = self.ViewObj.btn_LoginAction; 
    //[loginButton setTitle:@"Log out" forState:UIControlStateNormal]; 
    [loginButton setImage:[UIImage imageNamed:@"logout_FB.png"] forState:UIControlStateNormal]; 

    // Welcome message 
    [self showMessage:@"You're now logged in" withTitle:@"Welcome!"]; 

} 

ViewController.h

@interface ViewController : UIViewController 

@property (weak, nonatomic) IBOutlet UIButton *btn_LoginAction; 

ViewController.m

- (IBAction)buttonTouched:(id)sender 
{ 
    // If the session state is any of the two "open" states when the button is clicked 
    if (FBSession.activeSession.state == FBSessionStateOpen 
     || FBSession.activeSession.state == FBSessionStateOpenTokenExtended) { 

     // Close the session and remove the access token from the cache 
     // The session state handler (in the app delegate) will be called automatically 
     [FBSession.activeSession closeAndClearTokenInformation]; 

     // If the session state is not any of the two "open" states when the button is clicked 
    } else { 
     // Open a session showing the user the login UI 
     // You must ALWAYS ask for basic_info permissions when opening a session 
     [FBSession openActiveSessionWithReadPermissions:@[@"basic_info,email"] 
              allowLoginUI:YES 
             completionHandler: 
     ^(FBSession *session, FBSessionState state, NSError *error) { 

      // Retrieve the app delegate 
      AppDelegate* appDelegate = [UIApplication sharedApplication].delegate; 
      // Call the app delegate's sessionStateChanged:state:error method to handle session state changes 
      [appDelegate sessionStateChanged:session state:state error:error]; 
     }]; 
    } 
} 

我Simulator屏幕

enter image description here

+0

請妥善解決您的問題一點點清楚... –

+0

肯定阿曼Aggarwal。我的解釋中哪部分不清楚? –

+0

按鈕名稱沒有出現,但您在登錄和註銷時將圖像呈現給您的按鈕 –

回答

1

請嘗試下面的代碼設置按鈕圖像:

//登錄

[loginButton setBackgroundImage:[UIImage imageNamed:@"login_FB.png"] 
forState:UIControlStateNormal]; 

//退出

[loginButton setBackgroundImage:[UIImage imageNamed:@"logout_FB.png"] forState:UIControlStateNormal]; 

我們需要對了setBackgroundImage按鈕,設置標題不使用setImage。

+0

它不工作jorik。 –

相關問題