【发布时间】:2012-08-09 22:08:25
【问题描述】:
我尝试使用 NSSortDescriptor 对 NSMutableArray *friends, key:birthday, 按日期进行排序,我的 NSLog 中的所有生日都为空,但名称仍在记录中。如果我拔出我的 NSSortDescriptor,我的 NSLog 将再次给我这些值,想知道为什么我在通过 NSSortDescriptor 传递它们时会丢失这些值,以及我如何才能实现这一点。我使用 Hackbook 示例代码来学习 Facebook 集成,并修改了代码给我朋友的生日,并且我想让他们按照 1/1 - 12/31 的格式对 1 月 - 12 月进行排序是不是因为随机拉动朋友列表的结果数据?提前感谢您,一旦我们查明真相,我一定会接受!
******************************CODE TO PULL KEYS BIRTHDAY AND NAMES FROM GRAPH API ******
- (void)getUserFriends {
currentAPICall = kAPIGraphUserFriends;
HackbookAppDelegate *delegate = (HackbookAppDelegate *)[[UIApplication sharedApplication] delegate];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"name, birthday", @"fields", nil];
[[delegate facebook] requestWithGraphPath:@"me/friends" andParams:params andDelegate:self];
[self apiGraphFriends];
}
***********RANDOMIZE LIST OF FRIENDS NAMES W BIRTHDAYS AND PUSH TO VIEW CONTROLLER
NSMutableArray *friends = [[NSMutableArray alloc] initWithCapacity:1];
NSArray *resultData = [result objectForKey:@"data"];
if ([resultData count] > 0) {
for (NSUInteger i=0; i<[resultData count] && i < 1000; i++) {
[friends addObject:[resultData objectAtIndex:i]];
}
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"birthday"
ascending:TRUE];
[friends sortUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]];
[sortDescriptor release];
// LOG VALUES OF KEYS birthday and name FOR DEBUGGING
NSLog(@"name %@" , [friends valueForKey:@"name"]);
NSLog(@"birthday %@" , [friends valueForKey:@"birthday"]);
// Show the friend information in a new view controller
NSLog(@"Check#3");
APIResultsViewController *controller = [[APIResultsViewController alloc]
initWithTitle:@"Friends Birthdays"
data:friends action:@""];
[self.navigationController pushViewController:controller animated:YES];
[controller release];
} else {
[self showMessage:@"You have no friends."];
}
[friends release];
8/10 编辑在上面添加了代码,显示了我如何获得这些名字和生日,我相信它们都是http://developers.facebook.com/docs/reference/api/user/ 的 NSStrings 只需向下滚动到生日部分。我还想提一下,非常重要的是,我已经扩展了权限,这不是权限问题,当我尝试对数组进行排序时,我做错了,我相信我的经验不足是我自己最大的敌人。谢谢!
【问题讨论】:
-
您的代码没有任何明显错误。生日是 NSDate 对象吗?
-
这就是杀死我的原因,我只是无法弄清楚为什么在运行该 NSSortDescriptor 时它会丢弃“生日”的值,我将发布我进行查询的代码,因为它涉及 NSMutDict。这就是为什么我可能在这方面完全错了。
-
码猴,我之前看到你发了一些代码,但是我回来看的时候没看到,你删了吗?感谢你! *编辑不,我没有任何运气,现在我被困在一个布尔...也许你可以帮忙吗?大声笑
标签: objective-c ios xcode facebook-graph-api nsmutablearray