如何参考我在下面创建的NSDictionary * fbFriends
[FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSDictionary<FBGraphUser> *me = (NSDictionary<FBGraphUser> *)result;
// Store the Facebook Id
[[PFUser currentUser] setObject:me.objectID forKey:@"fbId"];
[[PFUser currentUser] saveInBackground];
// 1
FBRequest *friendsRequest = [FBRequest requestForGraphPath:@"/me/friends"];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary* result,
NSError *error) {
// 2
NSArray *friends = result[@"data"];
for (NSDictionary<FBGraphUser>* friend in friends) {
NSLog(@"Found a friend: %@", friend.name);
// 3
// Add the friend to the list of friends in the DataStore
[[DataStore instance].fbFriends setObject:friend forKey:friend.objectID];
}
// 4
// Callback - login successful
if ([delegate respondsToSelector:@selector(commsDidLogin:)]) {
[delegate commsDidLogin:YES];
}
}];
// Add the User to the list of friends in the DataStore
[[DataStore instance].fbFriends setObject:me forKey:me.objectID];
}
}];
在DataStore.h中我有
@property (nonatomic, strong) NSMutableDictionary *fbFriends;
我一直试图以多种方式引用它,但没有任何工作。我不知道我应该用什么钥匙 在我的tableviewcontroller中
cell.textLabel.text=[[DataStore instance].fbFriends objectForKey:self];
我想列出同样使用该应用的fb朋友的名字。我的NSLog显示我有朋友,但我不知道如何在表视图控制器单元格中显示它们
我正在使用Ray Wenderlichs教程http://www.raywenderlich.com/44833/integrating-facebook-and-parse-tutorial-part-2
中的代码这是字典的NSLog
Dictionary contents: {
10152183401605823 = {
id = 10152183401605823;
name = "John Gor";
};
10203978226397607 = {
"first_name" = Katie;
gender = female;
id = 10237890226397607;
"last_name" = James;
link = "https://www.facebook.com/app_scoped_user_id/10237890226397607/";
locale = "en_US";
name = "Katie James";
timezone = "-5";
"updated_time" = "2013-12-22T16:18:07+0000";
verified = 1;
};
答案 0 :(得分:0)
有几件事:
您发布的代码调用[[DataStore instance].fbFriends setObject: <some_value>];
只有在您创建了一个空字典并在某个时刻将其保存在数据存储的fbFriends属性中时,这才有效。声明属性是不够的,你必须使用new,dictionaryWithCapacity,alloc / init或类似的东西在某处分配一个空字典。
此代码:
cell.textLabel.text=[[DataStore instance].fbFriends objectForKey:self];
没有任何意义。你为什么要用#34; self&#34;作为你的fbFriends阵列的关键?自我可能是视图控制器。使用视图控制器作为字典的键是错误的。
您期望在字典中找到哪些键/值对?
您必须先了解字典中存储的数据,然后才能从中获取密钥/视频对。你有记录字典的内容吗?代码可能如下所示:
NSLog(@"Dictionary contents: %@", [DataStore instance].fbFriends);
在我看来,fbFriends是一个朋友对象(也是词典)的字典,以朋友ID作为fbFriends中每个条目的关键字存储。因此,即使您能够从fbFriends加载朋友对象,您也无法将fbFriends中的条目分配给您的标签文本。
您想在表格视图的标签文字中显示什么内容?
另外,你的fbFriends是一本字典。字典不是有序的,所以它们不适合提供表格视图。