我有一个默认的facebook sdk loginViewController,但在facebookSDK页面上的所有示例中,他们在同一个viewController中获取用户信息,所以如果我想存储所有用户信息(由loginViewController提取),我该怎么办?另一个viewControllers?
从loginViewController
获取用户代码- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
user:(id<FBGraphUser>)user {
self.profilePictureView.profileID = user.id;
self.nameLabel.text = [NSString stringWithFormat:@"Welcome,\n %@", user.name];
NSLog(@"%@ has been got from loginViewFetchedUserInfo function",user.name);
_loggedInUser = user;
}
// Implement the loginViewShowingLoggedInUser: delegate method to modify your app's UI for a logged-in user experience
- (void)loginViewShowingLoggedInUser:(FBLoginView *)loginView {
self.statusLabel.text = @"Click button below to continue";
[self.logoImage setHidden:YES];
[self.profilePictureView setHidden:NO];
[self.continueButton setHidden:NO];
//[self pushToMainTabsBarController];
}
// 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= @"Please login to continue!";
[self.logoImage setHidden:NO];
[self.profilePictureView setHidden:YES];
[self.continueButton setHidden:YES];
}
答案 0 :(得分:0)
在另一个视图控制器中,您只需要插入一个这样的属性
@property (nonatomic, strong) id<FBGraphUser> user;
然后例如,当您在第一个方法中获取用户数据时,将该属性设置为新的视图控制器(显然已经实例化):
_newViewController.user = user;
或者,如果您希望实例在另一时间使用新视图控制器,您可以在登录视图控制器中设置相同的属性以暂时存储用户数据(正如您已经使用_loggedInUser = user;
所做的那样)然后传递它在合适的时刻到新的视图控制器。
答案 1 :(得分:0)
您可以将其存储在Core Data中,然后在其他视图中进行检索,或者通过segue
方法将其传递给
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"ToOtherViewController"]) {
OtherViewController *OVC = (OtherViewController *)segue.destinationViewController;
OVC.user = user;
}
}
使用核心数据需要little reading。