0

我正在以一种迂回的方式来做这件事。我正在拉动我的应用程序的当前用户以及当前用户的 Facebook 朋友。

当您打印friendUsers [这是一个数组]时,您会得到:

"<PFUser:1234567:(null)> {\n    fbId = abcdefg;\n    username = ausername;\n}"
)

为了简单起见,我显然换掉了一些信息,但你明白了。

因此,如果我有很多用户的数组,我会想要提取 fbId,并查询 facebook 并让他们的个人资料图片显示在表格中。然后你可以点击他们的个人资料图片。这个想法是改变对象分配给谁。

我得到一个不兼容的指向整数转换的指针,将 NSIndexPath strong 发送到 .NSUInteger 类型的参数didSelectRowAtIndexPath

不仅如此,我还意识到我在这里只是选择了一个用户:

PFUser *facebookID = [[PFUser alloc] init];
    facebookID = [friendUsers objectAtIndex:0];

那是因为目前我只有一个其他用户安装了我的应用程序。我这样做只是为了查看我的应用在查询 Facebook 时是否正常工作。但是,如果有很多用户,我将如何获取所有的 facebookID?

#import "FacebookFriendViewController.h"
#import "MainQueryViewController.h"
#import <Parse/Parse.h>

@interface FacebookFriendViewController ()

@end

@implementation FacebookFriendViewController

@synthesize friendUsers;
@synthesize pic;
@synthesize object;

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];


    NSLog(@"This is what was passed to the view controller.");
    NSLog(@"Printing friendUsers: %@", friendUsers);
    NSLog(@"%@", object);

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1;
}

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

    NSLog(@"The count is... count=%d",[friendUsers count]);
    // Return the number of rows in the section.
    return [friendUsers count];


}

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

    static NSString *CellIdentifier = @"friendCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    PFUser *facebookID = [[PFUser alloc] init];
    facebookID = [friendUsers objectAtIndex:0];
    NSString *fbIdString = [[NSString alloc] init];
    fbIdString = [facebookID objectForKey:@"fbId"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

    }
    NSLog(@"This is a facebook ID:%@", fbIdString);
    NSURL *profilePictureURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large", fbIdString]];
    NSData *picData = [NSData dataWithContentsOfURL:profilePictureURL];
    UIImageView *fbPic = (UIImageView *)[self.view viewWithTag:1001];
    [fbPic setImage:[UIImage imageWithData:picData]];



    // Configure the cell...

    return cell;
}



#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    [object setObject:[friendUsers objectAtIndex:indexPath] forKey:@"assignedTo"];

}

@end

谢谢你的帮助

更新

根据 HRM 的询问,这里是发送到朋友选择器视图的内容。

 PF_FBRequest *request = [PF_FBRequest requestForMyFriends];
        [request startWithCompletionHandler:^(PF_FBRequestConnection *connection,
                                              id result,
                                              NSError *error) {
            if (!error) {
                // result will contain an array with your user's friends in the "data" key
                NSArray *friendObjects = [result objectForKey:@"data"];
                NSMutableArray *friendIds = [NSMutableArray arrayWithCapacity:friendObjects.count];
                // Create a list of friends' Facebook IDs
                for (NSDictionary *friendObject in friendObjects) {
                    [friendIds addObject:[friendObject objectForKey:@"id"]];
                }

                // Construct a PFUser query that will find friends whose facebook ids
                // are contained in the current user's friend list.
                PFQuery *friendQuery = [PFUser query];
                [friendQuery whereKey:@"fbId" containedIn:friendIds];

                // findObjects will return a list of PFUsers that are friends
                // with the current user
                NSArray *friendUsers = [friendQuery findObjects];



                NSLog(@"%@", friendUsers);


                [self performSegueWithIdentifier:@"sendToFriend" sender:friendUsers];
            }
        }];
4

1 回答 1

1

要解决您的不兼容指针问题,您必须传递indexPath.row给 cellForRowAtIndexPath。

您可以非常轻松地获取 fb 用户 ID: facebookID = [friendUsers objectAtIndex:indexPath.row];在 cellForRowAtIndexPath 方法中。

我希望这有帮助。

于 2013-04-24T04:50:32.803 回答