How to sort a NSArray alphabetically?

前端 未结 7 1225
借酒劲吻你
借酒劲吻你 2020-11-22 15:32

How can I sort an array filled with [UIFont familyNames] into alphabetical order?

7条回答
  •  星月不相逢
    2020-11-22 16:19

    -(IBAction)SegmentbtnCLK:(id)sender
    { [self sortArryofDictionary];
        [self.objtable reloadData];}
    -(void)sortArryofDictionary
    { NSSortDescriptor *sorter;
        switch (sortcontrol.selectedSegmentIndex)
        {case 0:
                sorter=[[NSSortDescriptor alloc]initWithKey:@"Name" ascending:YES];
                break;
            case 1:
                sorter=[[NSSortDescriptor alloc]initWithKey:@"Age" ascending:YES];
                default:
                break; }
        NSArray *sortdiscriptor=[[NSArray alloc]initWithObjects:sorter, nil];
        [arr sortUsingDescriptors:sortdiscriptor];
        }
    

提交回复
热议问题