FBFriendPickerViewController间歇性地加载一个空的tableview

时间:2013-02-07 17:59:58

标签: session facebook-ios-sdk

我使用FBFriendPickerViewController在用户登录后加载好友。但是,正在加载一个空表视图。来自fb的用户的朋友没有出现。 这是代码。

- (IBAction)inviteButtonTouchHandler:(id)sender {
        if (!_friendPickerController) {
            _friendPickerController = [[FBFriendPickerViewController alloc] initWithNibName:nil bundle:nil];
            _friendPickerController.delegate = self;
            _friendPickerController.title = @"Select friends";
            _friendPickerController.allowsMultipleSelection = NO;
        }
        [_friendPickerController clearSelection];
        [_friendPickerController loadData];
        [self presentViewController:_friendPickerController animated:YES completion:nil];
  }  

此代码在登录后调用,在Facebook教程后面的appDelegate中执行此操作 -

- (void)openSession
{
    NSArray *permissions = @[@"friends_about_me"];
    [FBSession openActiveSessionWithReadPermissions:permissions
                                       allowLoginUI:YES
                                  completionHandler:
     ^(FBSession *session,
       FBSessionState state, NSError *error) {
         [self sessionStateChanged:session state:state error:error];
     }];
}

1 个答案:

答案 0 :(得分:3)

您需要在viewController的viewDidLoad方法中添加以下代码。

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;
        }
    }];
}