UItableView 根据数据结构不同 会有不同样式 关键在两个代理 tableviewdelegate&tabledatasourse

下面代码是我实施的Group 在模拟器中 ios6.1和ios7

并且滚动后相应的section会“置顶”,效果不错哦!

核心代码:

  1. #import <UIKit/UIKit.h>
  2.  
  3. @interface AnnouncementViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>
  4. {
  5. UITableView *tableView_Inform;
  6. }
  7.  
  8. @end
  9. //////////////////////////////////////////////////////
  10.  
  11. - (void)viewDidLoad
  12. {
  13. [self.view addSubview: [NavView NavView_Title:@"通告"]];
  14. [super viewDidLoad];
  15. [self TableView];
  16. }
  17. -(void)TableView
  18. {
  19. if(StatusBar_System>)
  20. {
  21. moment_status_bar=;
  22. }
  23. tableView_Inform=[[UITableView alloc]initWithFrame:CGRectMake(, +moment_status_bar, ,Phone_Height-- )];
  24. [self.view addSubview:tableView_Inform];
  25. tableView_Inform.dataSource=self;
  26. tableView_Inform.delegate=self;
  27. }
  28. /*
  29. ios7以前的group 一般是圆角的,ios7以后没有圆角 苹果鼓励并支持更大的阅读面积 所以我把ios6的圆角也去掉了 也挺帅的 不是么
  30. */
  31. //每一个section中间的宽度 可以根据需要设定 如果第一个section不需要宽度 就return 0;
  32. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  33. {
  34. if (!section == ) {
  35.  
  36. return 44.0;
  37. } else {
  38. return 44.0;
  39. }
  40. }
  41. //一共有几组 返回有几个 section 块
  42. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  43. return ;
  44. }
  45. //每组有几行 返回 每个块 有几行cell
  46. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  47. return ;
  48. }
  49. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
  50. {
  51. NSArray *array=[NSArray arrayWithObjects:@"One",@"Two", @"Three",@"Four",nil];
  52. return [array objectAtIndex:section];
  53. }
  54. //cell注意数据结构的变化 indexPath.row 是循环变化的
    //这里cell 我是写死的 可以自定义哦哦
  55. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  56. static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
  57. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
  58.  
  59. SimpleTableIdentifier];
  60. if (cell == nil) {
  61.  
  62. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
  63.  
  64. reuseIdentifier: SimpleTableIdentifier] ;
  65. }
  66. NSLog(@"%d",indexPath.row);
  67. return cell;
  68. }
  69. - (void)didReceiveMemoryWarning
  70. {
  71. [super didReceiveMemoryWarning];
  72. // Dispose of any resources that can be recreated.
  73. }

附加 ios6和ios7的两个效果图

IOS UITableView Group&Section的更多相关文章

  1. iOS UITableView的Section Footer加入button

    郝萌主倾心贡献,尊重作者的劳动成果.请勿转载. 假设文章对您有所帮助,欢迎给作者捐赠.支持郝萌主,捐赠数额任意.重在心意^_^ 我要捐赠: 点击捐赠 Cocos2d-X源代码下载:点我传送 在处理UI ...

  2. IOS UITableView NSIndexPath属性讲解

    IOS UITableView NSIndexPath属性讲解   查看UITableView的帮助文档我们会注意到UITableView有两个Delegate分别为:dataSource和deleg ...

  3. 下拉刷新和UITableView的section headerView冲突的原因分析与解决方案

    UITableView:下拉刷新和上拉加载更多 [转载请注明出处] 本文将说明具有多个section的UITableView在使用下拉刷新机制时会遇到的问题及其解决方案. 工程地址在帖子最下方,只需要 ...

  4. iOS UITableView划动删除的实现

    标签:划动删除 iphone 滑动删除 ios UITableView 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://rainb ...

  5. 快速设置UITableView不同section对应于不同种类的cell

    快速设置UITableView不同section对应于不同种类的cell 本文主要是为了写明如何在UITableView中,一个section对应于一种类型的cell,写起来不凌乱. 在不封装任何类的 ...

  6. iOS UITableView Tips(2)

    #TableView Tips(2) (本来想一章就结束TableView Tips,但是发现自己还是太天真了~too young,too simple) ##架构上的优化 在Tips(1)中指出了一 ...

  7. ios 更改UITableview group形式 两个section之间的距离

    -(CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section { return 1.0 ...

  8. IOS UItableView得到group如何摆脱的剪裁线条样式问题

    在他们的定义UItableView什么时候,选择当style至Group时间,后常透明切割线依然,去除.只有再次刷新了BackgroundView它可以覆盖原来的 //取消切割线 UIView *vi ...

  9. iOS UITableView中关于cell里的按钮被点击时如何确定是哪一个section

    在section=10:row=1:的UITableView中,每一个cell都带有一个按钮,例如如下的图片一样每一个cell中都有一个“进入店铺的按钮”,但是如果我点击相应的cell要进入对应的店铺 ...

随机推荐

  1. 【转】jsp页面中jstl标签详解

    原文地址: JSLT标签库,是日常开发经常使用的,也是众多标签中性能最好的.把常用的内容,放在这里备份一份,随用随查.尽量做到不用查,就可以随手就可以写出来.这算是Java程序员的基本功吧,一定要扎实 ...

  2. java线性表学习笔记(一)

    线性表是一种按顺序储存数据是的常用结构,大多数的线性表都支持以下的典型操作: 从线性表提取插入删除一个数据: 找出线性表中的某一个元素: 找出线性表中的元素: 确定线性表中是否包含某一个元素,确定线性 ...

  3. Improved logging in Objective-C

    [Improved logging in Objective-C] Example of logging the current method and line number. Paste it in ...

  4. 动态生成xml文件

    使用xmlParser动态生成xml,输入的字符编码是gbk,结果怎么生成都不行,后来把输入转成utf8之后, 再生成就ok了

  5. Windows 2003 服务器安全设置-批处理 (附参考链接)

    长期维护windows服务器终结出来的安全设置批处理与大家分享,复制以下全部内容用记事本另存为bat或者cmd执行 ===================分隔符号=================== ...

  6. Python字典 (dictionary)

    字典dict,是Python唯一的标准mapping类型,也是内置在Python解释器中的. mapping object把一个可哈希的值(hashable value)映射到一个任意的object上 ...

  7. Codeforces 660 C. Hard Process (尺取)

    题目链接:http://codeforces.com/problemset/problem/660/C 尺取法 #include <bits/stdc++.h> using namespa ...

  8. ]用EnumChildWindows遍历窗口的方法

    最近项目有需要,得到一个非自己实现的窗口控件对象.于是想起曾经做过类似功能.总结如下: 调用EnumChildWindows(this->m_hWnd, EnumChildProc, NULL) ...

  9. UI进阶 文件管理器(NSFileManager)文件对接器(NSFileHandle)

    一.文件管理器与文件连接器之间的区别 文件管理器(NSFileManager) 此类主要是对文件进行的操作(创建/删除/改名等)以及文件信息的获取. 文件连接器(NSFileHandle) 此类主要是 ...

  10. CentOS6 下Vim安装和配置

    1.系统只安装了vim-minimal,执行以下命令安装另外两个组件 yum install vim-common yum install vim-enhanced 2.安装ctags yum ins ...