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)