Iphone 使用类对象按字母顺序为小对象排序NSMutableArray
我有一个包含属性类对象的数组,比如Iphone 使用类对象按字母顺序为小对象排序NSMutableArray,iphone,sorting,nsarray,Iphone,Sorting,Nsarray,我有一个包含属性类对象的数组,比如 for (int i=0; i<[eventList count]; i++) { NSDictionary *EventListDic=[eventList objectAtIndex:i]; eventData.eventID=[EventListDic objectForKey:@"event_id"]; eventData.eventsname=[EventListDic objectForKey:@"title"];
for (int i=0; i<[eventList count]; i++) {
NSDictionary *EventListDic=[eventList objectAtIndex:i];
eventData.eventID=[EventListDic objectForKey:@"event_id"];
eventData.eventsname=[EventListDic objectForKey:@"title"];
[self.arrEventDataList addObject:eventData];
[eventData release];
}
我想按事件名称对我的欠账清单进行排序。试试这个
NSSortDescriptor *sortByName = [NSSortDescriptor sortDescriptorWithKey:@"eventsname"
ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortByName];
NSArray *sortedArray = [arrEventDataList sortedArrayUsingDescriptors:sortDescriptors];
您将获得已排序的值。这将对你的arreventdata列表进行排序
试试这个
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"self" ascending:YES];
NSArray *sortedFloats = [eventData.eventsname sortedArrayUsingDescriptors:
[NSArray arrayWithObject:sortDescriptor]];
[sortDescriptor release];
// Put the two arrays into a dictionary as keys and values
NSDictionary *dictID = [NSDictionary dictionaryWithObjects:eventData.eventID forKeys:eventData.eventsname];
// Sort the second array based on the sorted first array
sortedID = [dictID objectsForKeys:sortedFloats notFoundMarker:[NSNull null]];
这与Xcode完全无关-如果你使用了另一个IDE,那也没什么区别。此外:“我用NSSortDescriptor试用过”-然后展示你试用过的代码。-“但它不起作用”-嗯,“它不起作用”是没有信息的,就好像你去看医生,在你告诉他“我感觉不舒服”后,就希望他能治好你的病一样。NSSortDescriptor*sortDescriptor=[[NSSortDescriptor alloc]initWithKey:eventData.eventsname升序:否];NSArray*orderedArray=[listArray SortedArray使用描述符:[NSArray arrayWithObject:sortDescriptor]];我使用了这个函数。@userXXX现在将它格式化并放入问题中,这样我就可以阅读它了。
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"self" ascending:YES];
NSArray *sortedFloats = [eventData.eventsname sortedArrayUsingDescriptors:
[NSArray arrayWithObject:sortDescriptor]];
[sortDescriptor release];
// Put the two arrays into a dictionary as keys and values
NSDictionary *dictID = [NSDictionary dictionaryWithObjects:eventData.eventID forKeys:eventData.eventsname];
// Sort the second array based on the sorted first array
sortedID = [dictID objectsForKeys:sortedFloats notFoundMarker:[NSNull null]];