objective c - Accessing descriptors in array of arrays -


i have mutable array containing arrays use in table view controller. arrays contain title , other information. want arrays in master array sorted alphabetically in terms of title contain. have assigned titles keys:

nsstring *title = @"objecttitle"; nsdictionary *dict = [nsdictionary dictionarywithobjectsandkeys:_storedtitle.text, title, nil]; nsarray *newarray = @[@"login", dict, _storedusername.text, _storedpassword.text]; 

i store newarray in masterarray , try sort array thus:

    //sort array alphabetically     nssortdescriptor *titledescriptor = [[nssortdescriptor alloc] initwithkey:@"objecttitle" ascending:yes];     nsarray *sortdescriptors = @[titledescriptor];     nsarray *sortedarray = [_masterarray sortedarrayusingdescriptors:sortdescriptors];      _masterarray = sortedarray.copy; 

this not working, have not specified index titledescriptor stored. how do this?

when accessing title @ given index (index) in master array done follows:

     nslog(@"%@", [[[_masterarray objectatindex:index] objectatindex:1] objectforkey:@"objecttitle"]); 

modified code this:-

nssortdescriptor *sorteddescriptor =         [[[nssortdescriptor alloc]          initwithkey:@"objecttitle"          ascending:yes                 selector:@selector(localizedcaseinsensitivecompare:)] autorelease];  nsarray * descriptors = [nsarray arraywithobjects:sorteddescriptor, nil];   nsarray * sortedarray =  [array sortedarrayusingdescriptors:descriptors];  nslog(@"%@",sortedarray); 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -