【问题标题】:My UITableView is displaying the wrong order of my FQL query [closed]我的 UITableView 显示我的 FQL 查询的错误顺序 [关闭]
【发布时间】:2013-12-09 18:01:53
【问题描述】:
            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;
}

------------- ProfileTableViewCell 的代码 @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个字。所以我可能需要拆分它,然后按姓氏排序。 (或第一个)

【问题讨论】:

  • 您所展示的只是一个 SQL 查询,但您的问题是关于以错误顺序显示数据的表视图。你甚至没有解释这张桌子有多乱。除非您提供更多详细信息,说明您想要什么顺序、获得什么以及如何为表格创建数据,否则没有人可以帮助您。
  • 名称的排序顺序不正确,如 FQL 所示。
  • 您确定您的 FQL 正确吗?
  • 我如何确认我的 FQL 是正确的?我找不到页面

标签: ios uitableview facebook-fql settings.bundle


【解决方案1】:
  1. 确保 FQL 正确
  2. 确保您的结果不会由字典或集合处理 - 这些不尊重项目的顺序(因为它们的数据类型),因此您将失去那里的排序
  3. 如果还是有问题,直接sort your array

【讨论】:

    猜你喜欢
    • 2015-12-22
    • 1970-01-01
    • 2013-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-07
    • 2021-01-05
    • 1970-01-01
    相关资源
    最近更新 更多