Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to sort an array by integer
    primarykey
    data
    text
    <p>i am trying to sort my score board but the score board is sorted by name but i want sort it by score i.e (high to low) score plese help to solve this.i stored the playername and score details in one label.<br> please help me thanks in advance</p> <p>asd 45 asd 66 rrr 55 tes 42</p> <p>i want to show like </p> <p>asd 66 rrr 55 asd 45 tes 42</p> <pre><code>-(void)btnSaveScore { if(!dictWinData) dictWinData = [[NSMutableDictionary alloc] init]; array = [[NSMutableArray alloc] init]; array = [[[NSUserDefaults standardUserDefaults] valueForKey:@"ScoreName"] mutableCopy]; if([array count] == 0) { array = [[NSMutableArray alloc] init]; } NSString *strName = [NSString stringWithFormat:@"%@",strNameOFPlayer]; NSString *strScore = [NSString stringWithFormat:@"%@",[NSString stringWithFormat:@"%d",iTap]]; int intScore = iTap; NSLog(@"iTap data is:--&gt; %d",intScore); if([strNameOFPlayer length]==7) [array addObject:[NSString stringWithFormat:@"%@ %@",strName,strScore]]; else if ([strNameOFPlayer length] == 6) [array addObject:[NSString stringWithFormat:@"%@ %@",strName,strScore]]; else if ([strNameOFPlayer length] == 5) [array addObject:[NSString stringWithFormat:@"%@ %@",strName,strScore]]; else if ([strNameOFPlayer length] == 4) [array addObject:[NSString stringWithFormat:@"%@ %@",strName,strScore]]; else if ([strNameOFPlayer length] == 3) [array addObject:[NSString stringWithFormat:@"%@ %@",strName,strScore]]; else if ([strNameOFPlayer length] == 2) [array addObject:[NSString stringWithFormat:@"%@ %@",strName,strScore]]; else if ([strNameOFPlayer length] == 1) [array addObject:[NSString stringWithFormat:@"%@ %@",strName,strScore]]; NSSortDescriptor *sorter = [[NSSortDescriptor alloc] initWithKey:@"self" ascending:YES]; NSArray *sorters = [[NSArray alloc] initWithObjects:sorter, nil]; [sorter release]; NSArray *sortedArray = [array sortedArrayUsingDescriptors:sorters]; [sorters release]; NSUserDefaults *dfltsData = [NSUserDefaults standardUserDefaults]; [dfltsData setObject:sortedArray forKey:@"ScoreName"]; // [dfltsData setObject:array forKey:@"ScoreCard"]; [dfltsData synchronize]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Score is saved." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil]; [alert show]; [alert release]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload