【问题标题】:Iphone Contact list. Sort TableView view alphabeticallyIphone 联系人列表。按字母顺序对 TableView 视图进行排序
【发布时间】:2013-03-27 01:11:18
【问题描述】:

我正在制作一个 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”数组进行排序 请帮忙!!!!!!!!!

【问题讨论】:

    标签: iphone objective-c sorting custom-object contact-list


    【解决方案1】:
    [self.elements sortUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"lastName" ascending:YES]]];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-04
      • 1970-01-01
      • 1970-01-01
      • 2013-05-02
      • 2014-02-08
      • 2011-07-28
      相关资源
      最近更新 更多