Iphone联系人列表.按字母顺序排序TableView视图



我正在制作一个IPHONE电话簿应用程序,它有一个联系人(对象)数组。我正在尝试对这个数组进行排序,以便它按字母顺序显示lastName

但是似乎什么都不起作用。我不确定我会把我的代码在"MasterViewController"。这是我的部分代码

我的对象如下所示。

@interface PhoneBookEntry : Person  
@property NSString *firstName;
@property NSString *lastName;
@property NSString *address;
@property NSString *phoneNumber;

@end

@interface MasterViewController : UITableViewController
@property NSMutableArray *elements;
@end

@implementation MasterViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.elements = [[NSMutableArray alloc] init];
}

假设数组中已经有元素。我需要对self。elements进行排序。lastName"按字母顺序排列请帮助! !

[self.elements sortUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"lastName" ascending:YES]]];

最新更新