IOS tableView的基本使用
tableView Style:Plain(头部标题 向上移 不会消失)
tableView Style:Grouped(头部标题 向上移 会 消失)
- #import "ViewController.h"
- #import "carGroup.h"
- @interface ViewController ()<UITableViewDataSource>
- @property (weak, nonatomic) IBOutlet UITableView *tableView;
- @property(nonatomic,strong) NSArray *carGroups;
- @end
- @implementation ViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- //设置数据源
- self.tableView.dataSource=self;
- }
- //隐藏状态栏
- -(BOOL)prefersStatusBarHidden
- {
- return YES;
- }
- -(NSArray *)carGroups
- {
- if(_carGroups==nil)
- {
- //初始化
- //德系品牌
- carGroup *car1=[[carGroup alloc]init];
- car1.title=@"德系品牌";
- car1.desc=@"德系品牌很好";
- car1.cars=@[@"奥迪", @"宝马", @"奔驰",];
- //日系品牌
- carGroup *car2=[[carGroup alloc]init];
- car2.title=@"日系品牌";
- car2.desc=@"日系品牌很好sssss";
- car2.cars=@[@"本田", @"丰田"];
- //欧系品牌
- carGroup *car3=[[carGroup alloc]init];
- car3.title=@"欧系品牌";
- car3.desc=@"欧系品牌很好yyyyyy";
- car3.cars=@[@"法拉力", @"兰博基尼",];
- _carGroups=@[car1,car2,car3];
- }
- return _carGroups;
- }
- /**一共有多少组数据*/
- -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return self.carGroups.count;
- }
- /**第section组有多少行*/
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- //取得第section级对应的模型
- carGroup *cg=self.carGroups[section];
- return cg.cars.count;
- }
- /**每一行显示怎样的内容(cell)*/
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- // UITableViewCell *cell=[[UITableViewCell alloc]initwithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
- UITableViewCell *cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
- //取出 模型indexpath.section组对应的模型
- carGroup *cg=self.carGroups[indexPath.section];
- //取车第indexpath.row这行对应的品牌名称
- NSString *car=cg.cars[indexPath.row];
- //设置cell显示的文字
- cell.textLabel.text=car;
- return cell;
- }
- /**第section组显示怎样的头部标题*/
- -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
- {
- carGroup *cg=self.carGroups[section];
- return cg.title;
- }
- /**第section组显示怎样的尾部标题*/
- -(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
- {
- carGroup *cg=self.carGroups[section];
- return cg.desc;
- }
IOS tableView的基本使用的更多相关文章
- ios tableview 上加 textfiled
ios tableview 上加 textfiled 首先附上我项目中用曾经用到的几张图 并说明一下我的用法: 图1: 图2: 图3: 心在你我说一下 我当初的实现 方法 ,希望能给你们一些 启 ...
- iOS TableView多级列表
代码地址如下:http://www.demodashi.com/demo/15006.html 效果预览 ### 一.需求 TableView多级列表:分级展开或合并,逐级获取并展示其子级数据,可以设 ...
- iOS tableview cell 的展开收缩
iOS tableview cell 的展开收缩 #import "ViewController.h" @interface ViewController ()<UITabl ...
- iOS tableview的常用delegate和dataSource执行顺序
在这次项目中遇到了一个特别奇葩的问题:表视图创建的cell在7以上的系统能正常运行显示,在模拟器上就不能正常实现......为解决这个问题,纠结了好久...... 对在7系统上不显示的猜测: 用mas ...
- IOS tableview下拉刷新上拉加载分页
http://code4app.com/ios/快速集成下拉上拉刷新/52326ce26803fabc46000000 刷新没用用插件,加载使用的MJ老师的插件. - (void)viewDidLoa ...
- iOS tableView 静态单元格的实现
本文转自:http://home.cnblogs.com/u/wendingding/ iOS开发UI篇—简单介绍静态单元格的使用 一.实现效果与说明 说明:观察上面的展示效果,可以发现整个界面是由一 ...
- iOS tableview 优化总结
根据网络上的优化方法进行了总括.并未仔细进行语言组织.正在这些优化方法进行学习,见另一篇文章 提高app流畅度 1.cell子控件创建写在 initWithStyle:reuseIdentifier ...
- 【转】ios tableView那些事(一)创建一个简单的tableView
工作也有半年多了!几乎每个项目中的会用到tableview这个神奇而好用的控件,在学习和工作中都会看别人的博客!对我有很大的帮助,就如同站在巨人的肩膀上的感觉吧 哈哈!于是决定重新开始写博客,希望能帮 ...
- iOS | TableView的优化
TableView是iOS组件中最常见.最重要的组件之一,在开发中常常用到,所以对其进行优化是一项必不可少的基本功. 主要从几个最常用的方面来对其优化: 1.重用机制 重用机制是cell最基础的一项优 ...
- iOS -- tableView顶部留白
最近iOS 11 下来之后需要适配系统,故此测试系统发现同一种机器上tableView与顶部控件,或者导航栏之间的有大量的留白: 这个问题是有的界面有,有的界面无: 修改与导航栏或者其他控件之间的距离 ...
随机推荐
- Android_靠谱的监听软键盘状态的方法
public class MyActivity extends AppCompatActivity { /** * 当前界面中的软件盘的状态 */private boolean isKeyBoardO ...
- 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 ]# ...
- Dev GridView RowCellClick事件与MouseDown事件
GridView处于可编辑状态,左键点击默认为“进入编辑”. 将GridView的OptionsColumn.AllowEdit设置为false后左键可触发RowCellClick.但有时候,既希望G ...
- Spring配置问题:The prefix "util" for element "util:map" is not bound.
在spring的头部文件中没有引入: xmlns:util=”http://www.springframework.org/schema/util” 原文:https://blog.csdn.net/ ...
- java——第十二章 异常处理和文本I/O
1.异常处理: 使用try_throw_catch块模块 优点:将检测错误(由被调用的方法完成)从处理错误(由调用方法完成)中分离出来. 例子: package test; import java.u ...
- java替换word2003
map.put("year", year); map.put("yearMonthDay", yearMonthDay); ...
- hdu 2222 ac自动机更新模板 for onSite contest
http://acm.split.hdu.edu.cn/showproblem.php?pid=2222 #include <cstdio> #include <cstdlib> ...
- [转]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 ...
- [转]javascript实现限制上传文件的大小
本文转自:http://www.micmiu.com/lang/javascript/js-check-filesize/ 目录 基本思路 示例 [一].基本思路 在FireFox.Chrome浏览器 ...
- WPF调用Win Form
WPF是win form的下一代版本,现在越来越多的公司使用WPF.如何兼容已有的使用win form开发的应用程序呢?下面有三种方式来在WPF中调用win form. 使用WPF中的WindowsF ...