0

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

但似乎没有任何效果。我不确定将代码放在“MasterViewController”中的哪个位置。这是我的代码的一部分

我的对象如下所示。

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

@结尾

@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”数组进行排序,请帮助!!!!!!!!!

4

1 回答 1

0
[self.elements sortUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"lastName" ascending:YES]]];
于 2013-03-27T01:19:42.407 回答