私はFacebookのグラフAPIに取り組んでいます。そして、私のアプリを使用しているユーザーのIDをすでに取得しています。ユーザーのIDとやりたいことを表示できます。テーブルビューの各セルに、良いユーザーのFBProfilePictureViewが表示されます。
[[FBRequest requestForMe] startWithCompletionHandler:
^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (!error) {}
NSString* fql =
@"SELECT uid FROM user WHERE is_app_user=true AND uid IN (SELECT uid2 FROM friend WHERE uid1 = me())";
[FBRequestConnection startWithGraphPath:@"/fql"
parameters:@{ @"q" : fql}
HTTPMethod:@"GET"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
FBRequest *fql = [FBRequest requestForGraphPath:@"fql"];
[fql.parameters setObject:@"SELECT uid,name,is_app_user FROM user WHERE is_app_user AND uid IN (SELECT uid2 FROM friend WHERE uid1 = me())" forKey:@"q"];
[fql startWithCompletionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
if (result) {
NSArray *arrayRsult = [result objectForKey:@"data"];
NSMutableArray *ids = (NSMutableArray *) [arrayRsult valueForKey:@"uid"];
NSMutableArray *names = (NSMutableArray *) [arrayRsult valueForKey:@"name"];
recentFriends = [[NSMutableArray alloc] init];
idFriends = [[NSMutableArray alloc] init];
for (NSDictionary *c in ids)
{
[idFriends addObject:c];
}
arrayLength = [recentFriends count];
NSLog(@"ids are : %@ ",idFriends);
NSLog(@"there are %i", arrayLength);
まず、このコードを使用して各セルに Facebook のプロフィール写真を表示します。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
FBProfilePictureView *prof = [[FBProfilePictureView alloc]initWithFrame:CGRectMake(5, 5, 30, 30)];
[[FBRequest requestForMe] startWithCompletionHandler:
^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (!error) {
prof.profileID = [user objectForKey:@"id"];
}
}];
[cell addSubview:prof];
}
カスタムセルとカスタムセルのペン先は使用しません。このテーブルの配列を作成する方法がわかりません。私はこのコードを試しました cell.imageView.image = [idFriends objectAtIndex:indexPath.row];
(idFriends は .h ファイルで __block NSMutableArray として宣言されています) 助けてくれてありがとう!