tableview 索引条问题
2015-08-13 17:31
176 查看
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
// 有问题的写法
#pragma mark -- 创建 section -(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView { return _sectionIndexArray; } - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{ for (int i = 0; i < _letterPatientsGroupArray.count; i++) { LetterPatients *letterPatients = [_letterPatientsGroupArray objectAtIndex:i]; if ((letterPatients.letterFirst > title) && i > 0) { return i - 1; } // lab.text = [NSString stringWithFormat:@" %@",letterPatients.letterFirst]; } return index; }
// 正确
#pragma mark -- 创建 section -(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView { return _sectionIndexArray; } - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{ //初始化索引 for (int i = 0; i < [_letterPatientsGroupArray count]; i++) { LetterPatients *info = _letterPatientsGroupArray[i]; if ([info.letterFirst isEqualToString:title]) { return i; } } return NSNotFound;; }
相关文章推荐
- 神经网络编程入门
- this
- MySql 定时任务 Event Scheduler
- MFC实现256色工具栏图标及工具栏提示信息
- CodeForces 5B - Center Alignment
- Spring---IOC简介
- 最优间隔分类、原始/对偶问题、SVM对偶—斯坦福ML公开课笔记7
- leetcode Minimum&&Max Depth of Binary Tree 求树的最小&&最大深度
- CoreImage 中的模糊滤镜
- [TroubleShooting] The remote copy of database xx has not been rolled forward to a point in time
- 《道德经》全文注释
- LeetCode OJ平台Sort Colors讨论主题算法
- 学习JAVA框架的心得体会
- kubernetes API Server 权限管理实践
- Android和服务器通信
- java输出获取英文字母
- 2015/8/13/客户端服务器数据库综合
- iOS设计模式汇总
- 程序员日记我们需要有条理的生活
- 【iOS官方文档翻译】UICollectionView与UICollectionViewFlowLayout