0

我无法显示列表朋友 facebook,我正在使用 FBRequest,我已经获得列表朋友但它没有显示在 UITableView

这是我的代码:

- (void)viewDidLoad
{
    [self.tblView setDataSource:self];
    [self.tblView setDelegate:self];
    [super viewDidLoad];
    [self loadFirst];
        _itemsNamesFriend = [[NSMutableArray alloc] init];
        if (FBSession.activeSession.isOpen) {

            FBRequest *friendRequest = [[FBRequest alloc] initWithSession:FBSession.activeSession graphPath:@"me/friends"];

            [friendRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                NSDictionary *resultDictionary = (NSDictionary *)result;
                _itemsNamesFriend = [resultDictionary objectForKey:@"data"];
                NSLog(@"%@",_itemsNamesFriend); //--> have data

            }];

            NSLog(@"%@",_itemsNamesFriend); //--> data is empty
            [self.tblView reloadData];
        }

}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//    NSLog(@"%d",_itemsNamesFriend.count);
    return _itemsNamesFriend.count;
}
4

1 回答 1

0

对块内变量所做的任何修改都不会显示在块外。因此,您需要使用 __block 声明它们,以便在块内完成的修改在外部可见。

这是您需要在 .h 文件中执行的操作

__block NSMutableArray* _itemsNamesFriend;

那应该可以解决您的问题。

于 2013-07-19T02:06:15.947 回答