这是一个2部分问题。
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
答案 0 :(得分:0)
在原始视图控制器中,使用prepareForSegue方法准备即将发生的视图控制器。我实际上和你一样有这种情况,这就是我所做的:
扩展您的DashboardViewController
对象以包含新属性,您可以在其中存储用户信息:
@property (nonatomic) id<FBGraphUser> *fbUserInfo;
在原始视图控制器和仪表板VC之间配置segue。
在原始视图控制器中,添加一个触发此segue的方法:
- (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;
}
}