2
我正在努力完成此任務。我做了一個FBRequest,看看誰(在我的臉書朋友)安裝了我的應用程序。顯示在uitableview中使用相同的朋友列表
這裏是我的代碼
-(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時,我想要顯示的數據不會出現..他們似乎爲空。
這是最後步驟,以結束這個項目的一部分,可惜我不能由我自己做這個
謝謝 !我忘了[self> tableView reloadData]; – RMS 2013-05-08 00:57:50
@RaphMaz很高興幫助。如果這解決了您的問題,請點擊我答案旁邊的複選標記以關閉問題。 – iwasrobbed 2013-05-08 01:04:34