真的被这件事难住了,需要一些帮助!我正在创建 UITableViewController 的子类来显示 FB 好友列表(FBFriendPickerViewController 对我有几个限制)。我能够检索一个 id 数组并按字母顺序对它们进行排序。
但是,仍然无法从这里找到一种方法来创建一个单独的字典,将 FB 用户划分为按字母顺序排列的部分以进行索引。
-(void)captureFacebookFriendUsers
{
//Issue a Facebook Graph API request
NSLog(@"%@", NSStringFromSelector(_cmd));
[FBRequestConnection startForMyFriendsWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error){
if (!error) {
NSLog(@"No error requesting friends");
friendsObjects = [result objectForKey:@"data"]; //Objects are id<FBGraphUser>
friendsNames = [NSMutableArray arrayWithCapacity:friendsObjects.count];
NSMutableArray *friendIds = [NSMutableArray arrayWithCapacity:friendsObjects.count];
//Create a list of friends' Facebook IDs
NSSortDescriptor *firstNameDescriptor = [[NSSortDescriptor alloc]initWithKey:@"first_name" ascending:YES];
friendsObjects = [friendsObjects sortedArrayUsingDescriptors:@[firstNameDescriptor]];
for (NSDictionary *friendObject in friendsObjects) {
[friendIds addObject:[friendObject objectForKey:@"id"]];
[friendsNames addObject:[friendObject objectForKey:@"first_name"]];
}
}
感谢您花时间阅读本文!