#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的教程说,但由于某种原因标签不出现,为什么这可能是任何帮助吗? 实际的登录和登出工作,但标签中的文本标签和更改不起作用。
从以往的经验来看,它应该工作,因为逻辑看起来不错。
你在厦门国际银行/故事板添加这些标签?他们连接吗?委托方法是否被调用?你订阅了委托协议吗? –
您可能忘了将这些标签从.storyboard /拖到您的视图控制器中。xib文件并将它们连接到IBOutlets – Daniel
Facebook的iOS开发站点上的教程,它说这些标签应该以编程方式工作,并且不需要将它们连接到故事板。与添加但在故事板上不可见的登录视图一样。 –