问题
I'm using the following code to call the Facebook request method, the request calls the delegate method which returns an NSDictionary object with a key labelled 'data'. I then get the friends array by calling NSArray *data = [result objectForKey:@"data"];
Then the code loops through that array and extracts the names outputting them to the console.
The problem I'm having is how do I send this array to a table where the user can select a friend and post to their FB wall.
thanks for any help :)
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[[delegate facebook] requestWithGraphPath:@"me/friends" andDelegate:self];
// get the array of friends
NSArray *data = [result objectForKey:@"data"];
NSMutableArray *array = [NSMutableArray array];
for (int i = 0; i < data.count; i++){
id object = [data objectAtIndex:i];
[array addObject:[object objectForKey:@"name"]];
}
// output the array of friends
NSLog(@"list of friends %@", array);
I'm thinking I need something like (I'm not sure what to put in the objectAtIndex:????? part:
[self apiDialogFeedFriend:[[data objectAtIndex:**?????**] objectForKey:@"id"]];
and then
[self apiGraphFriends];
回答1:
get Facebook friends photo and name . Stroe in array
FBRequest* friendsRequest = [FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary* result,
NSError *error) {
friends = [result objectForKey:@"data"];
arr_FaceBookFriendProfileImg = [[NSMutableArray alloc] init];
arr_FaceBookFriendName = [[NSMutableArray alloc]init];
for (NSDictionary<FBGraphUser>* friend in friends) {
NSString *str_FacebookFriendNames;
str_FacebookFriendNames = friend.name;
NSString *userPhotoUrl = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?", friend.id];
NSURL *url_FriendProfileImage = [NSURL URLWithString:userPhotoUrl];
[arr_FaceBookFriendName addObject:str_FacebookFriendNames];
[arr_FaceBookFriendProfileImg addObject:url_FriendProfileImage];
}
// [table_facebookFriends reloadData];
}];
and display the TableView
cell.lbl_FriendsProfileName.text = [arr_FaceBookFriendName objectAtIndex:indexPath.row];
来源:https://stackoverflow.com/questions/11646746/how-to-send-an-array-to-a-table-where-the-user-can-select-a-friend-and-post-to-t