问题描述
我正在排序 NSFetchedResultController
数据。我需要按照他们的名字对数据排序。但是,有一些没有名字的条目。
I'm working on sorting NSFetchedResultController
data. I need to sort data by their first name. However, there are some entries with no first name.
我需要无名字对象出现在列表的底部,而不是顶部。使用当前代码,当我按名字排序列表时,无名字单元格放在顶部。
I need the "no first name" objects to appear the bottom of the list, rather than the top. With the current code, when I sort the list by first name, the "no first name" cells are placed at the top.
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Contacts"];
request.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"firstName" ascending:YES]];
_FRC = [[NSFetchedResultsController alloc] initWithFetchRequest:request
managedObjectContext:MOC
sectionNameKeyPath:nil cacheName:nil];
_FRC.delegate = self;
推荐答案
在与同事协商后更新:)
首先,你是在说一个空格的字符串中的空格还是'nil',这是一个没有价值的属性?
Update after some consulting with colleagues :)
First, are you talking about "blank" as in a string with spaces in it or 'nil' which is a property with no value at all?
一个想法是添加一个 BOOL
调用 hasFirstName
首先在 hasFirstName
,然后在 firstName
上排序。
An idea that came up would be to add a BOOL
called hasFirstName
and then sort first on the hasFirstName
and then sort on firstName
.
这篇关于使用NSSortDescriptor将'nil'值保留在列表的底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!