【问题标题】:Display list of friends using same in uitableview在uitableview中显示使用相同的朋友列表
【发布时间】:2013-05-08 00:13:38
【问题描述】:

我正在努力完成这项工作。我创建了一个 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 请求之外编写 NSLogs 时,我想显示的数据没有出现。它们似乎为空。

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

【问题讨论】:

    标签: iphone ios xcode facebook facebook-fql


    【解决方案1】:

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

    __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

    【讨论】:

    • 谢谢!我忘记了 [self->tableView reloadData];
    • @RaphMaz 很高兴为您提供帮助。如果这解决了您的问题,请点击我的答案旁边的复选标记以结束问题。
    猜你喜欢
    • 1970-01-01
    • 2012-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多