iphone - how to sort an NSMutableArray of Arrays? -


i'm trying sort array of table view no luck, how i'm trying it:

    - (void) compare     {            nsmutablearray *temp = [[nsmutablearray alloc] initwithobjects: nil];          [temp addobjectsfromarray:[self displayedobjects]];           int = [[self displayedobjects] count];          (int = 0; < (a - 1); i++){              (int j = 0; j <= (i^2); j++) {                  nsstring *temp1 = [temp objectatindex:i];                  nsstring *temp2 = [temp objectatindex:i+1];                  if (temp1 > temp2) {                      [movieindex replaceobjectatindex:i withobject:temp2];                      [movieindex replaceobjectatindex:i+1 withobject:temp1];                  }             }           }          [self movieindex];          [[self tableview] reloaddata];      } 

displayedobjects array of array user can add new objects. objects movie instances in form of:

the tableview cell has title of movie. "in" title there tableview details movie. want sort displayed movies titles in ascending order code doesn't seem work.


displayedobjects set of 3 nsstrings , 1 nsnumber. gets objects form following class:

#import <foundation/foundation.h>  @interface movie : nsobject     {         nsstring *_title;         nsstring *_gender;         nsstring *_location;         nsnumber *_publicationyear;     }  @property (nonatomic, retain) nsstring *location; @property (nonatomic, retain) nsstring *title; @property (nonatomic, retain) nsstring *gender; @property (nonatomic, retain) nsnumber *publicationyear;  + (id)moviewithtitle:(nsstring *)title                  gender:(nsstring *)gender                    year:(nsuinteger)year                 location:(nsstring *)location;  - (id)initwithtitle:(nsstring *)title                  gender:(nsstring *)gender                    year:(nsuinteger)year                 location:(nsstring *)location;  @end 

because no 1 has suggested yet, , love blocks, i'll suggest block alternative same thing suggested:

[myarray sortusingcomparator:^nscomparisonresult(id obj1, id obj2) {      ... }]; 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -