myuiwindow.m

来自「使用NSSortDescriptor类对NSArray数组中的数据按照规则排序。」· M 代码 · 共 24 行

M
24
字号
#import "MyUIWindow.h"#import "SortDescriptorAppDelegate.h"@implementation MyUIWindow- (void)sortByName:(id)sender{	SortDescriptorAppDelegate* delegate = [[UIApplication sharedApplication] delegate];	NSSortDescriptor* nameDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"name_" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)] autorelease];	NSArray* sortDescriptors = [NSArray arrayWithObject:nameDescriptor];	NSArray* sortedArray = [delegate.employeeArray_ sortedArrayUsingDescriptors:sortDescriptors];}- (void)sortByAge:(id)sender{	SortDescriptorAppDelegate* delegate = [[UIApplication sharedApplication] delegate];		NSSortDescriptor* ageDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"age_" 																   ascending:NO] autorelease]; 	NSArray* sortDescriptors = [NSArray arrayWithObject:ageDescriptor]; 	NSArray* sortedArray = [delegate.employeeArray_ sortedArrayUsingDescriptors:sortDescriptors];	}@end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?