按字母顺序对数组排序并在表视图中显示数组值

编程入门 行业动态 更新时间:2024-10-27 14:34:57
本文介绍了按字母顺序对数组排序并在表视图中显示数组值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我必须打印 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]];

更多推荐

按字母顺序对数组排序并在表视图中显示数组值

本文发布于:2023-11-30 00:57:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648194.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   并在   视图   字母   顺序

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!