UITableView section header 显示在最上面
2014-02-28 12:00
441 查看
或许大家都是有过这样的情况:
在一个UITableView中有N个section,然后每个section下面有1个或者多个cell,在section里面添加一个点击事件按钮,在点击之后将对应的section中的cell显示出来,平时是隐藏的。
可是显示出来之后,section并不是显示在tableview 的最上面,而是哪里打开,哪里显示,找了很久找到了这样的方法,将指定的section放在指定的位置,下面贴代码:
//点击section之后,将这个section放到tableview的最上面一行
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:button.tag];
CGRect frame = [tbList rectForSection:indexPath.section];
[tbList setContentOffset:CGPointMake(0, frame.origin.y) animated:YES];
上面的代码放在按钮的点击事件中,点击事件全部如下:
在一个UITableView中有N个section,然后每个section下面有1个或者多个cell,在section里面添加一个点击事件按钮,在点击之后将对应的section中的cell显示出来,平时是隐藏的。
可是显示出来之后,section并不是显示在tableview 的最上面,而是哪里打开,哪里显示,找了很久找到了这样的方法,将指定的section放在指定的位置,下面贴代码:
//点击section之后,将这个section放到tableview的最上面一行
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:button.tag];
CGRect frame = [tbList rectForSection:indexPath.section];
[tbList setContentOffset:CGPointMake(0, frame.origin.y) animated:YES];
上面的代码放在按钮的点击事件中,点击事件全部如下:
- (void)imgBtnClick:(UIButton *)button { iSection = button.tag; int sectionIndex = ((UIButton*)button).tag; if (sectionIndex<0) { sectionIndex = -sectionIndex; } if (flag[sectionIndex]) { for (int i=0; i<[dicIntro count]; i++) { flag[i]=FALSE; } if(isClick == TRUE) { isClick = FALSE; } } else { for (int i=0; i<[dicIntro count]; i++) { flag[i]=FALSE; } isClick = TRUE; flag[sectionIndex] = !flag[sectionIndex]; } [tbList reloadData]; //点击section之后,将这个section放到tableview的最上面一行 NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:button.tag]; CGRect frame = [tbList rectForSection:indexPath.section]; [tbList setContentOffset:CGPointMake(0, frame.origin.y) animated:YES]; }大家不要忘记把代码放在【tblist reloadData】之后,这样可以让cell的展开之间互不干扰,
相关文章推荐
- UILabel 的键盘操作
- 【翻译】自定义 UIViewController Transitions
- uint8_t数据类型
- 2217: Rescue The Princess(UPC)
- make出错 ./configure: error: SSL modules require the OpenSSL library.
- Ext.isEmpty( Mixed value, [Boolean allowBlank] ) 用法
- 本地通知(UILocalNotification)的学习和使用(通过本地通知实现提醒功能)
- JAVA hdu 3279 Nth Largest Value
- RCP: MANIFEST.MF, plugin.xml, build.properties三种文件的区别
- IOS学习笔记(七)之UISegmentedControl分段控件的基本概念和使用方法
- IOS学习笔记(七)之UISegmentedControl分段控件的基本概念和使用方法
- Servlet的request.getRemoteAddr()方法回去地址是0:0:0:0:0:0:0:1
- android Build手机基本信息
- 泛型与容器(4)——Queue
- NGUI 拖拽丢弃实现
- 从客户端中检测到有潜在危险的Request.Form值的解决方法
- iOS开发xcode报错:"xxxxxx"has been modified since the precompiled header was built
- iOS开发xcode报错:"xxxxxx"has been modified since the precompiled header was built
- Your build settings specify a provisioning profile with the UUID, no provisioning profile was
- UITableView,UIScrollView,UITableViewCell