显示索引
来源:互联网 发布:逛遍淘宝 编辑:程序博客网 时间:2024/05/21 21:42
//汉字索引
- (void)viewDidLoad
{
[superviewDidLoad];
NSString *path = [[NSBundlemainBundle] pathForResource:@"city"ofType:@"plist"];
NSArray *cities = [NSArrayarrayWithContentsOfFile:path];
self.keys = [[[NSMutableArrayalloc]init]autorelease];
//创建26个可变数组
NSMutableDictionary *dic = [[NSMutableDictionaryalloc]init];
for (char character ='a'; character <= 'z'; character++) {
NSMutableArray *array = [[NSMutableArrayalloc]init];
[dicsetObject:array forKey:[NSStringstringWithFormat:@"%c",character]];
[arrayrelease];
[self.keysaddObject:[NSStringstringWithFormat:@"%c",character]];
}
//将数据按拼音首字母分别放入数组
for (NSString *cityin cities) {
//获取拼音首字母
NSString *initial = [NSStringstringWithFormat:@"%c",pinyinFirstLetter([citycharacterAtIndex:0])];
NSMutableArray *array = [dic objectForKey:initial];
[arrayaddObject:city];
}
//将空组去掉
for (char character ='a'; character <= 'z'; character++) {
NSString *key = [NSStringstringWithFormat:@"%c",character];
NSArray *array = [dic objectForKey:key];
if (!array.count) {
[dicremoveObjectForKey:key];
}
}
self.keys = [[dic.allKeyssortedArrayUsingSelector:@selector(compare:)]mutableCopy];
//self.keys = [[dic allKeys] mutableCopy];;
self.list = dic;
[dicrelease];
}
//显示索引行
-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return self.keys;
}
- (void)viewDidLoad
{
[superviewDidLoad];
NSString *path = [[NSBundlemainBundle] pathForResource:@"sortednames"ofType:@"plist"];
self.names = [NSDictionarydictionaryWithContentsOfFile:path];
self.keys = [self.namesallKeys];
//将key按照字母表升序排列
self.keys = [self.keyssortedArrayUsingSelector:@selector(compare:)];
}
- (void)didReceiveMemoryWarning
{
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)dealloc{
[superdealloc];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.names.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSString *currentKey = [self.keysobjectAtIndex:section];
NSArray *currentGroup = [self.namesobjectForKey:currentKey];
return currentGroup.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier =@"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellIdentifier]autorelease];
}
NSString *currentKey = [self.keysobjectAtIndex:indexPath.section];
NSArray *currentGroup = [self.namesobjectForKey:currentKey];
NSString *currentName = [currentGroup objectAtIndex:indexPath.row];
cell.textLabel.text = currentName;
return cell;
}
-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return self.keys;
}
- 显示索引
- 显示索引
- 索引对应显示隐藏
- mysql 索引 创建 删除 显示
- [IOS]UITableView分区+索引显示
- MySQL:给表建立索引及索引的显示
- MySQL:给表建立索引及索引的显示
- SQL Server 2005 显示索引碎片
- 显示游标通过索引遍历数据
- 自开发显示表索引程序
- Lucene索引,查询及高亮显示
- 03-UITableView索引栏显示自定义图片
- UITableView分组列表,显示右侧索引
- photoshop图片显示为索引,解决办法
- 如何显示sql server表的索引信息?
- 把结点按索引是奇、偶数来分列显示
- 大数据量显示列表的页面(建索引)
- Arcgis MOBILE某些图层无法显示的问题索引
- IOS系列——公用属性autoresizingMask的详细介绍
- html文件图标异常的解决办法(转)
- hadoop批量安装第三方包
- 如何实现Oracle数据库之间的数据同步?
- 随机过程及其在金融领域中的应用 第二章 习题 及 答案
- 显示索引
- 【数据结构】静态查找_Search
- EXT中为Grid添加合计行
- Android手机开机动画制作
- hdu2570
- Oracle 基础知识之查看用户,用户权限,用户表空间,用户默认表空间
- SouthidcEditor编辑器如何支持上传png图片
- Linux scp 使用详解
- oracle创建job错误