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对此进行排序?这个名字只有一个字。所以我可能需要拆分它然后按姓氏排序。 (或第一个)
答案 0 :(得分:1)