2014-02-19 80 views
1
#import "whoViewController.h" 

@interface whoViewController() 

@property (nonatomic,strong) IBOutlet FBProfilePictureView *profilePictureView; 
@property (nonatomic,strong) IBOutlet UILabel *nameLabel; 
@property (nonatomic,strong) IBOutlet UILabel *statusLabel; 

@end 

上面應該將標籤添加到視圖中。Facebook登錄集成,以編程方式添加UILabel不起作用

@implementation whoViewController 


- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
// Do any additional setup after loading the view, typically from a nib. 
FBLoginView *loginView = [[FBLoginView alloc] init]; 
loginView.readPermissions = @[@"basic_info", @"email", @"user_likes"]; 
loginView.center = self.view.center; 
loginView.delegate = self; 
[self.view addSubview:loginView]; 
} 

- (void)didReceiveMemoryWarning 
{ 
[super didReceiveMemoryWarning]; 
// Dispose of any resources that can be recreated. 
} 

// This method will be called when the user information has been fetched 
- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView 
         user:(id<FBGraphUser>)user { 
self.profilePictureView.profileID = user.id; 
self.nameLabel.text = user.name; 
} 

// Implement the loginViewShowingLoggedInUser: delegate method to modify your app's UI for a 
    logged-in user experience 
- (void)loginViewShowingLoggedInUser:(FBLoginView *)loginView { 
self.statusLabel.text = @"You're logged in as"; 
} 

// Implement the loginViewShowingLoggedOutUser: delegate method to modify your app's UI for a 
logged-out user experience 
- (void)loginViewShowingLoggedOutUser:(FBLoginView *)loginView { 
self.profilePictureView.profileID = nil; 
self.nameLabel.text = @""; 
self.statusLabel.text= @"You're not logged in!"; 
} 
@end 

我實現了上面的,因爲它在Facebook的教程說,但由於某種原因標籤不出現,爲什麼這可能是任何幫助嗎? 實際的登錄和登出工作,但標籤中的文本標籤和更改不起作用。

從以往的經驗來看,它應該工作,因爲邏輯看起來不錯。

+0

你在廈門國際銀行/故事板添加這些標籤?他們連接嗎?委託方法是否被調用?你訂閱了委託協議嗎? –

+0

您可能忘了將這些標籤從.storyboard /拖到您的視圖控制器中。xib文件並將它們連接到IBOutlets – Daniel

+0

Facebook的iOS開發站點上的教程,它說這些標籤應該以編程方式工作,並且不需要將它們連接到故事板。與添加但在故事板上不可見的登錄視圖一樣。 –

回答

0

要整合Facebook SDK你需要下面遵循以下5個步驟,如果您有任何疑問,採取在Github上FbLoginIntegrationSample一看,審查Facebook開發(以下引用)入門部分:

1-下載並安裝Facebook的SDK

2-獲取Facebook應用ID(在Facebook登錄和在App儀表盤創建一個新的應用程序)

3-配置你的Xcode項目

  • 導入FacebookSDK.framework到項目
  • 配置的.plist文件(添加FacebookAppID和FacebookDisplayName)

5-開始編碼!

  • 導入FacebookSDK.framework到項目
  • 參考FBLoginViewDelegate到主視圖類(可能whoViewController.h)
  • 鏈接nameLabel,statusLabel和profilePictureView向本刊記者標籤(profilePictureView必須鏈接到一個UIView對象)
  • 配置的.plist文件(添加FacebookAppID和FacebookDisplayName)

還有一個提示:

1-記得設置一個LoginView幀的尺寸和位置:

loginView.frame = CGRectOffset(loginView.frame,(self.view.center.x - (loginView.frame.size.width/2)) ,5);

參考文獻:

示例項目

https://github.com/carantes/FbLoginIntegrationSample

配置:

https://developers.facebook.com/docs/ios/login-tutorial

+0

我一直按照教程,我只是卡在最後的部分,它顯示個人資料圖片等..登錄的人。 –

+0

請檢閱教程,並確保您參考視圖控制器上的代表 - > LoginUIViewController:UIViewController 和AppDelegate中的[FBLoginView類] didFinishLaunchingWithOptions函數 – carantes

+0

您可以提供任何調試信息,也許您可​​以添加一些輸出字符串(NSLog)loginViewFetchedUserInfo只是爲了確保函數調用 – carantes

相關問題