将Facebook登录信息传递给第二个视图
这是一个2部分问题。将Facebook登录信息传递给第二个视图
1.)一旦用户登录到应用程序,我想导航到DashboardViewController
。但是,我最后会发出警告。
警告:尝试在其针对目前 不在窗口 层次!
如何解决这个问题?
2.)我想通过(id<FBGraphUser>)user
到DashboardViewController
,我该怎么做到这一点?
的代码如下:
-(void)viewWillAppear:(BOOL)animated{ //[self toggleHiddenState:YES];
self.lblLoginStatus.text = @"";
self.loginButton.delegate = self;
self.loginButton.readPermissions = @[@"public_profile", @"email"];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Private method implementation
-(void)toggleHiddenState:(BOOL)shouldHide{
self.lblUsername.hidden = shouldHide;
self.lblEmail.hidden = shouldHide;
self.profilePicture.hidden = shouldHide;
}
#pragma mark - FBLoginView Delegate method implementation
-(void)loginViewShowingLoggedInUser:(FBLoginView *)loginView{
self.lblLoginStatus.text = @"You are logged in.";
[self toggleHiddenState:NO];
}
-(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"];
//
[self performSelector:@selector(displayDashboard) withObject:nil afterDelay:0.5];
}
-(void)displayDashboard{
DashboardViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"DashboardSegue"];
[[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentViewController:vc animated:YES completion:nil];
}
-(void)loginViewShowingLoggedOutUser:(FBLoginView *)loginView{
self.lblLoginStatus.text = @"You are logged out";
[self toggleHiddenState:YES];
}
-(void)loginView:(FBLoginView *)loginView handleError:(NSError *)error{
NSLog(@"OKKKKK %@ ", [error localizedDescription]);
}
@end
回答:
在您的始发视图控制器,使用prepareForSegue方法准备即将到来的视图控制器。其实我有相同的情况下,你,这是我做的:
扩展您DashboardViewController
对象包括一个新的属性,在这里你可以存储用户信息:
@property (nonatomic) id<FBGraphUser> *fbUserInfo;
配置之间的SEGUE您原始视图控制器和仪表板VC。
在你发起的视图控制器,添加将触发此赛格瑞的方法:
- (void)displayAnotherVC:(YourClass *)post { [self performSegueWithIdentifier:@"showCommentsSegue" sender:post];
}
在你发起VC,超控器的prepareForSegue
方法:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ if([segue.identifier isEqualToString:@"yourSegue"]){
YourCustomViewController *userProfileViewController = (YourCustomViewController *)segue.destinationViewController;
userProfileViewController.yourUserInfoProperty = (YourClass *)sender;
}
}
以上是 将Facebook登录信息传递给第二个视图 的全部内容, 来源链接: utcz.com/qa/264815.html