iOS中Tableview右边有字母检索 点击可以直接定位显示的问题
2014-11-25 14:09
399 查看
在做项目的过程中,我遇到这样一个问题,就是本身的tableview 调用
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
方法的时候,最后几个位置点击后不能准确定位,比如说“#” 不管我如何点击“#”都无法把其对应的列表项显示出来,所以我自己在
- (NSInteger) tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
方法中重写了一些方法 代码如下
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
方法的时候,最后几个位置点击后不能准确定位,比如说“#” 不管我如何点击“#”都无法把其对应的列表项显示出来,所以我自己在
- (NSInteger) tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
方法中重写了一些方法 代码如下
- (NSInteger) tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {<span style="white-space:pre"> </span> //1.获取当前index的section的original的y //2.用tableview.contentsize.height减去y,得到lefty //3.如果lefty>=tableview.frame.size.height 滚动lefty个单位 //4.如果lefty<tableview.frame.size.height 滚动tableview.contentsize.height-tableview.frame.size.height float y = [self getYOffSet:index title:title]; if (tableView.contentSize.height-y>=tableView.frame.size.height) { [tableView setContentOffset:CGPointMake(0, y) animated:NO]; }else{ [tableView setContentOffset:CGPointMake(0, tableView.contentSize.height-tableView.frame.size.height) animated:NO]; } return NSNotFound; } -(float)getYOffSet:(NSInteger)index title:(NSString *)title{
//这里的offy = 100 是我在这个tableview最上面加了两个section 不在这个计算之内 显示了别的东西 对于不需要添加特别提示等//显示,可以设置为0
float offY = 100; int count = 0;
//对应的所有内容的高度 float addOffy = 0;
//对应标题下内容不为空 例:以a开头的内容有aaa,abc,abcd 则a标题下不为空,addTitleCount加1 计数用 通过这个计算一共有
//多少项内不为空 总共占用多少header高度 最后一句中得22是我定义的一个viewforHeader的高度
float addTitleCount = 0;
//sectionTitles 是从a-z加上#之后的列表
//datasource 是对应我的没个section中有几项内容的数据 for (NSString * string in self.sectionTitles) { if ([string isEqualToString:title]) { break; } addOffy+=50*[[self.dataSource objectAtIndex:count] count]; if ([[self.dataSource objectAtIndex:count] count]!=0) { addTitleCount++; } count++; } return offY+22*(addTitleCount)+addOffy; }
相关文章推荐
- 【iOS】地图定位无效及点击设置隐私定位直接闪退问题
- iOS中一个tableView中显示两种cell的问题
- tableview属性 不显示cell分割线,右边小箭头取消选中 iOS 新手笔记
- iOS 不同按钮点击显示不同的tableview数据
- Ios 该图显示其出现的相关问题定义UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
- 当tableview滑到底部,点击cell出现的下拉框无法显示的问题
- iOS中Tableview右边检索背景颜色
- Tableview最后一行无法显示或者显示不全的问题IOS
- ios在tableview里面加subview后在ip4和ip5上显示不一样的问题
- tableview索引添加一个显示点击或滑动到哪个字母的控件
- iOS点击TableView的cell显示弹出动画
- iOS 使用tableview 代码布局时,tableViewCell宽度问题,运行在iPhone 6plus 仍然显示320
- iOS 9下 tableView cell 显示不正常 问题
- IOS开发之tableView点击行跳转并带有“显示”更多功能
- iOS 在tableView上添加button导致按钮没有点击效果和不能滑动的问题
- iOS tableView上刷新显示下载进度的问题
- iOS tableView上拉刷新显示下载进度的问题及解决办法
- iOS点击TableView的cell显示弹出动画
- IOS中TableView的cell显示问题
- iOS 解决tableView和点击手势冲突问题