-2
            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

The UITableView is displaying the wrong order. How can I fix it to display the correct order?

--- CODE FOR 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;
}

------------- Code to ProfileTableViewCell @interface ProfileTableViewCell : UITableViewCell {

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

}

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

@end

My result is a tableview of friends that are always in the same sort order

Here is the list of my friends

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;
}

How do I sort this with my NSPredicate? The name is just 1 word. So I may need to split it and then sort by last name. (or first)

software is fun
  • 7,286
  • 18
  • 71
  • 129
  • All you have shown is a SQL query but your question is about a table view showing data in the wrong order. You don't even explain how out of order the table is. Unless you provide more details about what order you want and what you get and how you create your data for the table, no one can help you. – rmaddy Dec 09 '13 at 18:26
  • The names are not in the correct sort order as indicated by the FQL. – software is fun Dec 09 '13 at 18:36
  • Are you sure your FQL is correct? – Sam Jarman Dec 09 '13 at 19:29
  • how can i confirm my FQL is correct? I can't find the page – software is fun Dec 09 '13 at 19:52

1 Answers1

1
  1. Make sure the FQL is correct
  2. Make sure your results don't get handled by a dictionary or set - these don't respect order of the items (because of their data type) so you'll lose ordering there
  3. If it's still a problem, simply sort your array
Community
  • 1
  • 1
Sam Jarman
  • 7,277
  • 15
  • 55
  • 100