开发者

How to sort an NSMutableArray List of objects in alphabetical order

开发者 https://www.devze.com 2022-12-26 21:11 出处:网络
I have an object with different values that is name,nameid, lifebeging,lifeEndiging .... etc, for loop

I have an object with different values that is name,nameid, lifebeging,lifeEndiging .... etc,

for loop
{
    // here i will get name, ids, other value for each object
    Search *Obj=[artistslist objectAtIndex:i];
}
0 obj.name=  //string values1 get from parser
1 obj.name=   //string values1
2 obj.name=  //string values1
3 obj.name=  //string values1
4 obj.name=  //string values1

I am getting values in the artistList then i need to sort only by name not other feilds

when i use this below statement

[artistsList sor开发者_如何学CtUsingSelector:@selector(NSOrderedAscending:)];

i am getting exception here ,it is not working.


isn't the correct selector to use localizedCaseInsensitiveCompare:?


NSOrderedAscending is not a selector, it's an enumeration constant and is one of the three possible return values the selector you do specify should return. For NSStrings, caseInsensitiveCompare: is a good one, or as jrtc27 suggests localizedCaseInsensitiveCompare: if you are sorting to present to the user. If not a string, you can define your own method that compares two objects and returns NSOrderedAscending, NSOrderedDescending or NSOrderedSame.


From where you store the data in artistlist?

If you store it from Database then u can use ORDER BY query to sort...

0

精彩评论

暂无评论...
验证码 换一张
取 消