tableView  Style:Plain(头部标题 向上移 不会消失)

tableView  Style:Grouped(头部标题 向上移 会 消失)

  1. #import "ViewController.h"
  2. #import "carGroup.h"
  3.  
  4. @interface ViewController ()<UITableViewDataSource>
  5. @property (weak, nonatomic) IBOutlet UITableView *tableView;
  6.  
  7. @property(nonatomic,strong) NSArray *carGroups;
  8.  
  9. @end
  10.  
  11. @implementation ViewController
  12.  
  13. - (void)viewDidLoad {
  14. [super viewDidLoad];
  15. //设置数据源
  16. self.tableView.dataSource=self;
  17. }
  18.  
  19. //隐藏状态栏
  20. -(BOOL)prefersStatusBarHidden
  21. {
  22. return YES;
  23. }
  24.  
  25. -(NSArray *)carGroups
  26. {
  27. if(_carGroups==nil)
  28. {
  29. //初始化
  30. //德系品牌
  31. carGroup *car1=[[carGroup alloc]init];
  32. car1.title=@"德系品牌";
  33. car1.desc=@"德系品牌很好";
  34. car1.cars=@[@"奥迪", @"宝马", @"奔驰",];
  35. //日系品牌
  36. carGroup *car2=[[carGroup alloc]init];
  37. car2.title=@"日系品牌";
  38. car2.desc=@"日系品牌很好sssss";
  39. car2.cars=@[@"本田", @"丰田"];
  40. //欧系品牌
  41. carGroup *car3=[[carGroup alloc]init];
  42. car3.title=@"欧系品牌";
  43. car3.desc=@"欧系品牌很好yyyyyy";
  44. car3.cars=@[@"法拉力", @"兰博基尼",];
  45. _carGroups=@[car1,car2,car3];
  46. }
  47. return _carGroups;
  48. }
  49.  
  50. /**一共有多少组数据*/
  51. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  52. {
  53.  
  54. return self.carGroups.count;
  55. }
  56.  
  57. /**第section组有多少行*/
  58. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  59. {
  60. //取得第section级对应的模型
  61. carGroup *cg=self.carGroups[section];
  62. return cg.cars.count;
  63. }
  64.  
  65. /**每一行显示怎样的内容(cell)*/
  66. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  67. {
  68. // UITableViewCell *cell=[[UITableViewCell alloc]initwithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
  69.  
  70. UITableViewCell *cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
  71.  
  72. //取出 模型indexpath.section组对应的模型
  73. carGroup *cg=self.carGroups[indexPath.section];
  74. //取车第indexpath.row这行对应的品牌名称
  75. NSString *car=cg.cars[indexPath.row];
  76.  
  77. //设置cell显示的文字
  78. cell.textLabel.text=car;
  79.  
  80. return cell;
  81. }
  82.  
  83. /**第section组显示怎样的头部标题*/
  84. -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
  85. {
  86. carGroup *cg=self.carGroups[section];
  87. return cg.title;
  88. }
  89. /**第section组显示怎样的尾部标题*/
  90. -(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
  91. {
  92. carGroup *cg=self.carGroups[section];
  93. return cg.desc;
  94.  
  95. }

IOS tableView的基本使用的更多相关文章

  1. ios tableview 上加 textfiled

    ios tableview 上加 textfiled 首先附上我项目中用曾经用到的几张图  并说明一下我的用法: 图1: 图2: 图3: 心在你我说一下  我当初的实现 方法 ,希望能给你们一些  启 ...

  2. iOS TableView多级列表

    代码地址如下:http://www.demodashi.com/demo/15006.html 效果预览 ### 一.需求 TableView多级列表:分级展开或合并,逐级获取并展示其子级数据,可以设 ...

  3. iOS tableview cell 的展开收缩

    iOS tableview cell 的展开收缩 #import "ViewController.h" @interface ViewController ()<UITabl ...

  4. iOS tableview的常用delegate和dataSource执行顺序

    在这次项目中遇到了一个特别奇葩的问题:表视图创建的cell在7以上的系统能正常运行显示,在模拟器上就不能正常实现......为解决这个问题,纠结了好久...... 对在7系统上不显示的猜测: 用mas ...

  5. IOS tableview下拉刷新上拉加载分页

    http://code4app.com/ios/快速集成下拉上拉刷新/52326ce26803fabc46000000 刷新没用用插件,加载使用的MJ老师的插件. - (void)viewDidLoa ...

  6. iOS tableView 静态单元格的实现

    本文转自:http://home.cnblogs.com/u/wendingding/ iOS开发UI篇—简单介绍静态单元格的使用 一.实现效果与说明 说明:观察上面的展示效果,可以发现整个界面是由一 ...

  7. iOS tableview 优化总结

    根据网络上的优化方法进行了总括.并未仔细进行语言组织.正在这些优化方法进行学习,见另一篇文章 提高app流畅度 1.cell子控件创建写在 initWithStyle:reuseIdentifier ...

  8. 【转】ios tableView那些事(一)创建一个简单的tableView

    工作也有半年多了!几乎每个项目中的会用到tableview这个神奇而好用的控件,在学习和工作中都会看别人的博客!对我有很大的帮助,就如同站在巨人的肩膀上的感觉吧 哈哈!于是决定重新开始写博客,希望能帮 ...

  9. iOS | TableView的优化

    TableView是iOS组件中最常见.最重要的组件之一,在开发中常常用到,所以对其进行优化是一项必不可少的基本功. 主要从几个最常用的方面来对其优化: 1.重用机制 重用机制是cell最基础的一项优 ...

  10. iOS -- tableView顶部留白

    最近iOS 11 下来之后需要适配系统,故此测试系统发现同一种机器上tableView与顶部控件,或者导航栏之间的有大量的留白: 这个问题是有的界面有,有的界面无: 修改与导航栏或者其他控件之间的距离 ...

随机推荐

  1. Android_靠谱的监听软键盘状态的方法

    public class MyActivity extends AppCompatActivity { /** * 当前界面中的软件盘的状态 */private boolean isKeyBoardO ...

  2. tomcat+nginx+memcache

    tomcat安装 tar zxf jdk-7u79-linux-x64.tar.gz -C /usr/local/ cd /usr/local/ ln -s jdk1.7.0_79/ java ]# ...

  3. Dev GridView RowCellClick事件与MouseDown事件

    GridView处于可编辑状态,左键点击默认为“进入编辑”. 将GridView的OptionsColumn.AllowEdit设置为false后左键可触发RowCellClick.但有时候,既希望G ...

  4. Spring配置问题:The prefix "util" for element "util:map" is not bound.

    在spring的头部文件中没有引入: xmlns:util=”http://www.springframework.org/schema/util” 原文:https://blog.csdn.net/ ...

  5. java——第十二章 异常处理和文本I/O

    1.异常处理: 使用try_throw_catch块模块 优点:将检测错误(由被调用的方法完成)从处理错误(由调用方法完成)中分离出来. 例子: package test; import java.u ...

  6. java替换word2003

    map.put("year", year);            map.put("yearMonthDay", yearMonthDay);         ...

  7. hdu 2222 ac自动机更新模板 for onSite contest

    http://acm.split.hdu.edu.cn/showproblem.php?pid=2222 #include <cstdio> #include <cstdlib> ...

  8. [转]Passing data between pages in JQuery Mobile mobile.changePage

    本文转自:http://ramkulkarni.com/blog/passing-data-between-pages-in-jquery-mobile/ I am working on a JQue ...

  9. [转]javascript实现限制上传文件的大​​小

    本文转自:http://www.micmiu.com/lang/javascript/js-check-filesize/ 目录 基本思路 示例 [一].基本思路 在FireFox.Chrome浏览器 ...

  10. WPF调用Win Form

    WPF是win form的下一代版本,现在越来越多的公司使用WPF.如何兼容已有的使用win form开发的应用程序呢?下面有三种方式来在WPF中调用win form. 使用WPF中的WindowsF ...