2015-06-28 79 views
1

這是一個2部分問題。將Facebook登錄信息傳遞給第二個視圖

1.)一旦用戶登錄到應用程序,我想導航到DashboardViewController。但是,我最後會發出警告。

警告:嘗試在其針對目前 不在窗口 層次!

如何解決這個問題?

2.)我想通過(id<FBGraphUser>)userDashboardViewController,我該怎麼做到這一點?

的代碼如下:

-(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

在您的始發視圖控制器,使用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; 
     } 
    } 
+0

無法添加Segue公司,因爲它不是一個UIButton,但一個視圖已經到位。 – Illep

+0

@Illep嗨。您應該能夠從您的原始視圖控制器添加一個segue到您的儀表板視圖控制器,您的案例(我想)從VC提示登錄儀表板VC。您的登錄控制器肯定有辦法確定登錄事件成功完成的時間,並且在那裏您可以觸發performSegueWithIdentifier方法。 –

+0

是的,我嘗試過。但是,我仍然得到相同的警告。 – Illep

相關問題