按字母顺序对数组排序并在表视图中显示数组值 [英] Sorting array in alphabetic order and displaying array values in table view
本文介绍了按字母顺序对数组排序并在表视图中显示数组值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须打印 NSMutableArray * lstAirports;
我的对象数组将在表视图单元格中打印所有记录
my array of object it print all record in table view cell
我想按字母顺序对单元格值进行排序.
I want to sort my cell value in alphabetical order.
该怎么做,请帮助一些未按字母顺序显示的代码
how to do that please some help this code not given me display in alphabetical order
这是我的控制器类代码
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return app.lstAirports.count;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
}
airport *a=(airport*)[app.lstAirports objectAtIndex:indexPath.row];
NSLog(@"str:%@",a);
cell.textLabel.text =a.Name;
cell.detailTextLabel.text=a.Code;
// Configure the cell...
return cell;
}
推荐答案
您可以轻松地对 NSMutableArray
进行排序:
You can easily sort a NSMutableArray
:
NSSortDescriptor *nameSort = [NSSortDescriptor sortDescriptorWithKey:@"Name" ascending:YES];
[lstAirports sortUsingDescriptors:[NSArray arrayWithObject:nameSort]];
这篇关于按字母顺序对数组排序并在表视图中显示数组值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文