簡體   English   中英

在表格視圖中顯示一些Facebook朋友的個人頭像(帶有ID)

[英]Display profile picture of some facebook friends (with the id) in a tableview

我在facebook graph 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)感謝您的幫助!

是的,您可以在UITableViewCell顯示用戶的個人資料圖片,您可以使用Cell的默認ImageView。 您可以通過以下方式獲取用戶的個人資料圖片及其Facebook ID

要獲取個人資料的小圖/縮略圖圖像,請使用

http://graph.facebook.com/<Friends Facebook ID>/picture?type=small

您也可以嘗試在type ,normal,large,square中使用以下參數

NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://graph.facebook.com/517267866/picture?type=small"]];
UIImage *profilePic = [UIImage imageWithData:imageData];

給定的代碼將從URL中獲取圖像並將該UIImage分配給您的UIImageView

如果您想了解更多詳細信息,請點擊這里閱讀文檔

cell.imageView.image = profilePic;

實際上,使用“ http://graph.facebook.com/ / picture?type = small”來獲取用戶甚至他們的朋友的個人資料圖片的速度很慢。

將FBProfilePictureView對象添加到視圖的一種更好,更快的方法,並在它的profileID屬性中分配用戶的Facebook ID。

例如:FBProfilePictureView * friendsPic;

friendsPic.profileID = @“ 1379925668972042”;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM