2012-12-23 49 views
0

我使用sdk 3.1並試圖使用friendpickercontroller,但不知何故表格正在我的應用程序加載空。FriendPickerViewController不加載

這是我的代碼,你能給出提示的原因嗎?

感謝

- (void) loadFacebookFriendsPicker:(UINavigationController *)senderNavigationController { 

    if (!FBSession.activeSession.isOpen) { 
     // if the session is closed, then we open it here, and establish a handler for state changes 
     [FBSession.activeSession openWithCompletionHandler:^(FBSession *session, 
                  FBSessionState state, 
                  NSError *error) { 
      switch (state) { 
       case FBSessionStateClosedLoginFailed: 
       { 
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" 
                     message:error.localizedDescription 
                     delegate:nil 
                   cancelButtonTitle:@"OK" 
                   otherButtonTitles:nil]; 
        [alertView show]; 
       } 
        break; 

       default: 
        break; 
      } 
     }]; 
    } 

    if (self.friendPickerController == nil) { 
     // Create friend picker, and get data loaded into it. 
     self.friendPickerController = [[FBFriendPickerViewController alloc] init]; 
     self.friendPickerController.title = @"Pick Friends"; 
     self.friendPickerController.delegate = self; 
    } 

    [self.friendPickerController loadData]; 
    [self.friendPickerController clearSelection]; 

    [senderNavigationController pushViewController:self.friendPickerController animated:YES]; 

} 

回答

0

應該不是你的friendPickerController在完成處理?你現在這樣做的方式,當你訪問它時,friendPickerController將是零,因爲完成處理程序是異步執行的。

使用條件FBSessionStateOpen將您的friendPickerController登錄移動到switch case塊中。事情是這樣的:

switch (state) { 
     case FBSessionStateOpen: { 

if (self.friendPickerController == nil) { 
     // Create friend picker, and get data loaded into it. 
     self.friendPickerController = [[FBFriendPickerViewController alloc] init]; 
     self.friendPickerController.title = @"Pick Friends"; 
     self.friendPickerController.delegate = self; 
    } 

    [self.friendPickerController loadData]; 
    [self.friendPickerController clearSelection]; 

    [senderNavigationController pushViewController:self.friendPickerController animated:YES]; 

} 

(不知道這裏雖然叫pushViewController)

0

你可能需要有這項功能在你的應用程序代理

// FBSample logic 
// In the login workflow, the Facebook native application, or Safari will transition back to 
// this applicaiton via a url following the scheme fb[app id]://; the call to handleOpenURL 
// below captures the token, in the case of success, on behalf of the FBSession object 
- (BOOL)application:(UIApplication *)application 
      openURL:(NSURL *)url 
    sourceApplication:(NSString *)sourceApplication 
     annotation:(id)annotation { 
    return [FBAppCall handleOpenURL:url sourceApplication:sourceApplication]; 
}