我是以迂回的方式做这件事。我正在吸引当前用户的用户以及当前用户的Facebook好友。
当你打印friendUsers [这是一个数组]时,你会得到这个:
"<PFUser:1234567:(null)> {\n fbId = abcdefg;\n username = ausername;\n}"
)
我显然为了简单而换掉了一些信息,但你明白了。
因此,如果我有很多用户的数组,我会想要拉取fbId,并查询facebook并获取他们的个人资料照片以显示在表格中。然后你可以点击他们的个人资料照片。我们的想法是改变对象的分配对象。
我得到一个不兼容的指向整数转换的指针,将NSIndexPath强发送到didSelectRowAtIndexPath
中NSUInteger类型的参数。
不仅如此,我在这里意识到我只是在这里选择一位用户:
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];
}
}];
答案 0 :(得分:1)
要修复不兼容的指针问题,必须将indexPath.row
传递给cellForRowAtIndexPath。
你可以很容易地抓住fb用户名:
在cellForRowAtIndexPath方法中facebookID = [friendUsers objectAtIndex:indexPath.row];
。
我希望这会有所帮助。