2

这是我显示组合框的代码:

self.records = [[NSMutableArray alloc]
                      initWithArray:[mylist componentsSeparatedByString:@","]];
[self.recordsCombo addItemsWithObjectValues:self.records];
4

2 回答 2

2

您永远不会对组合框的项目进行排序。实际上,您对数组进行排序,它是组合框的数据源。

与您的情况一样,您需要对组合框进行排序self.records,然后将添加项添加到组合框中。

self.records = [[NSMutableArray alloc]
                  initWithArray:[mylist componentsSeparatedByString:@","]];

self.records = [self.records sortedArrayUsingSelector:@selector(compare:)];

[self.recordsCombo addItemsWithObjectValues:self.records];
于 2014-12-10T09:01:28.980 回答
0

实际上这里已经介绍了按字母顺序排序:按字母顺序排序数组

否则,您总是可以实现自己的排序算法,例如 Quicksort 或类似的。取决于你的技能和需求。

于 2014-12-10T09:48:16.820 回答