我的UITableView显示错误的FQL查询顺序

时间:2013-12-09 18:01:53

标签: ios uitableview facebook-fql settings.bundle

            if(sort)
            {
                fql1 = [NSString stringWithFormat:@"SELECT uid,pic_square, name,online_presence FROM user WHERE is_app_user AND uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) ORDER BY last_name"];
            } else {
                fql1 = [NSString stringWithFormat:@"SELECT uid,pic_square, name,online_presence FROM user WHERE is_app_user AND uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) ORDER BY first_name"];
            }
            NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                            fql1, @"q",
                                            nil];// fql query to fetch the user friend's

UITableView显示错误的顺序。如何修复它以显示正确的顺序?

--- UITableView的代码

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ProfileTableViewCell * cell = nil;
    NSString *cellid = @"ProfileTableViewCell";
    cell = [tableView dequeueReusableCellWithIdentifier:cellid];

    if (cell == nil) {
        cell = [[ProfileTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid];
    }

    [cell setSelectionStyle:UITableViewCellSelectionStyleBlue];

    Friends *friendsObj = [self.friendsArray objectAtIndex:indexPath.row];
    [cell setCellContentWithuser:friendsObj];

    return cell;
}

------------- CodeTableViewCell的代码     @interface ProfileTableViewCell:UITableViewCell     {

    __weak IBOutlet UIImageView * imgvwUserPhoto;
    IBOutlet UILabel * labelForUserName;
    IBOutlet UIImageView * imgvwOnlinePresence;

}

- (void) setCellContentWithuser:(Friends*)friendsObj;

@end

我的结果是朋友的桌面视图总是处于相同的排序顺序

这是我朋友的名单

Fa Hu
Ma Ku
Me Ma
Me Sh
Sy Ma

------ ProfileTableViewCell

-(NSArray *)getAllFriendsfromFriendsTable{

    NSFetchRequest *request = [self getBasicRequestForEntityName:@"Friends"];
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"status=='1'"];
    NSSortDescriptor *catrgoryDescriptor = [[NSSortDescriptor alloc] initWithKey:@"facebook_name" ascending:YES];
    NSArray *sortDescriptors = @[catrgoryDescriptor];
    [request setSortDescriptors:sortDescriptors];
    [request setPredicate:predicate];
    NSArray *results = [_managedObjectContext executeFetchRequest:request error:nil];
    return results;
}

如何使用NSPredicate对此进行排序?这个名字只有一个字。所以我可能需要拆分它然后按姓氏排序。 (或第一个)

1 个答案:

答案 0 :(得分:1)

  1. 确保FQL正确
  2. 确保您的结果不会被字典或集合处理 - 这些不符合项目的顺序(因为它们的数据类型)所以您将失去在那里的订购
  3. 如果仍然存在问题,只需sort your array