我正在尝试用Facebook好友列表填充UITabelView。我已经检查了所有相关问题并尝试了所有答案,但是,它仍然无法正常工作。 这段简单的代码浪费了我的时间已经超过4个小时了。与Facebook好友填充UITableView
@interface InviteViewController()
{
__block NSArray *friends;
__block NSMutableArray *mArray;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
FBRequest* friendsRequest = [FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary* result,
NSError *error) {
friends = [result objectForKey:@"data"];
NSLog(@"Found: %i friends",friends.count);
for (NSDictionary<FBGraphUser>* friend in friends) {
NSLog(@"I have a friend named %@ with id %@", friend.name, friend.id);
[mArray addObject:friend.name];
}
}];
NSLog(@"%d",mArray.count);
return mArray.count;
}
,这里是我的控制台日志:
2014-01-12 20:18:21.429 PixidizeStoryBoard[26269:60b] 0
2014-01-12 20:18:21.742 PixidizeStoryBoard[26269:60b] Found: 1 friends
2014-01-12 20:18:21.744 PixidizeStoryBoard[26269:60b] I have a friend named Siavash ALp with id 1524650444
谢谢。我用另一种方式解决了,在加载(segue)UITableView之前,我设法获取好友列表,然后将prepareForSegue方法中的朋友数组传递给UITableView,并且它完美地工作。 – user2427421