创建一个不同的数组来支持您的表格视图,如下所示:
NSDictionary* obj1 = [NSDictionary dictionaryWithObject: [NSDate date] forKey: @"birthday"];
NSDictionary* obj2 = [NSDictionary dictionaryWithObject: [NSDate dateWithTimeIntervalSince1970: 0] forKey: @"birthday"];
NSDictionary* obj3 = [NSDictionary dictionaryWithObject: @"wow" forKey: @"no_birthday"];
NSArray* all = [NSArray arrayWithObjects: obj1, obj2, obj3, nil];
NSArray* onlyWithBirthday = [all valueForKeyPath: @"@unionOfObjects.birthday"];
如果您需要表格视图的完整对象,请继续执行以下代码:
NSPredicate* filter = [NSPredicate predicateWithFormat: @"SELF.birthday IN %@", onlyWithBirthday];
NSArray* datasource = [all filteredArrayUsingPredicate: filter];
然后,您可以应用您选择的排序方法。