显示在uitableview中使用相同内容的朋友列表

时间:2013-05-08 00:13:38

标签: iphone ios xcode facebook facebook-fql

我正在努力完成这项工作。我已经建立了一个FBRequest来查看谁(在我的facebook朋友中)安装了我的应用程序。

这是我的代码

-(void)viewDidload
{


    [[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) {
                                   if(error) {
                                       // NSLog(@"Problem");
                                   }
                                   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) {
                                           //NSLog(@"result:%@", result);

                                           //ON PARSE LE RESULT

                                           NSArray *arrayRsult = [result objectForKey:@"data"];
                                           NSMutableArray *ins = (NSMutableArray *) [arrayRsult valueForKey:@"is_app_user"];
                                           NSMutableArray *ids = (NSMutableArray *) [arrayRsult valueForKey:@"uid"];
                                           NSMutableArray *names = (NSMutableArray *) [arrayRsult valueForKey:@"name"];

                                           NSMutableArray *recentFriends = [[NSMutableArray alloc] init];
                                           NSMutableArray *idFriends = [[NSMutableArray alloc] init];
                                           NSMutableArray *nameFriends = [[NSMutableArray alloc] init];


                                           // ON A LE NOMBRE D'USER

                                           for (NSDictionary *d in ins)
                                           {
                                               [recentFriends addObject:d];
                                               [recentFriends removeObjectIdenticalTo:[NSNull null]];



                                           }

                                           // ON A LES IDS


                                           for (NSDictionary *e in ids)
                                           {
                                               [idFriends addObject:e];



                                           }
                                           // ON A LES NOMS

                                           for (NSDictionary *e in names)
                                           {
                                               [nameFriends addObject:e];



                                           }

                                           NSUInteger arrayLength = [recentFriends count];

                                           NSLog(@"ids are : %@ ",idFriends);
                                           NSLog(@"names are %@",nameFriends );

                                           NSLog(@"there are %i", arrayLength);


                                           data = [NSArray arrayWithObjects:nameFriends, nil];
                                           displayData = [[NSMutableArray alloc]initWithArray:data];

                                       }

                                       else {


                                           NSLog(@"problem , bullshit");}
                                   }];
                               }
          ];}];

    data = [NSArray arrayWithObjects:nameFriends, nil];
    displayData = [[NSMutableArray alloc]initWithArray:data];

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{



    UITableViewCell *cell = [[UITableViewCell alloc]
                             initWithStyle:UITableViewCellStyleDefault
                             reuseIdentifier:@"cell"];





    cell.textLabel.text = [displayData  objectAtIndex:indexPath.row];

    return cell;
}

  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {

    return [displayData count];

   }

在控制台中,我有id,拥有应用程序的人数及其名称。 现在,我想在tableView中显示NameFriends MutableArray的结果。

当我在facebook请求之外编写NSLog时,我想显示的数据没有出现......它们似乎是空的。

这是结束这部分项目的最后一步,遗憾的是我自己无法做到这一点

1 个答案:

答案 0 :(得分:0)

如果您希望能够在块中设置实例变量的值,则必须将其声明为:

__block data;
__block displayData;

由于代码中没有显示,我假设您在界面中声明了这些变量。

此外,我不确定为什么你在块之外的viewDidLoad方法的末尾有这个,因为它基本上什么都不做,应该删除:

data = [NSArray arrayWithObjects:nameFriends, nil];
displayData = [[NSMutableArray alloc]initWithArray:data];

更多信息:http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/Blocks/Articles/bxVariables.html