UI_UITableView_搭建
创建 tableView
UITableViewStyle 有两种选择
#pragma mark - 创建 tableView
- (void)createTableView
{
// 枚举类型共同拥有两个
self.mainTableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
[self addSubview:self.mainTableView];
}
根视图控制器遵守协议
@interface RootViewController () <UITableViewDataSource, UITableViewDelegate>
- (void)viewDidLoad {
[super viewDidLoad];
// 设置数据源代理
self.rootView.mainTableView.dataSource = self;
// 设置 delegate
self.rootView.mainTableView.delegate = self;
self.title = @"联系人";
}
重写代理方法
返回分组的个数
#pragma -mark 返回分组的个数
// 默觉得 1
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
}
每一个分组显示多少行数据 必须
#pragma mark - 每一个分组显示多少行数据 *必须*
// dataSource 下方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.nameArray.count;
}
每行显示什么内容 必须
#pragma mark - 每行显示什么内容 *必须*
// dataSource 下方法
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// 四种类型
// UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil];
// static 作用
/**
* 1、清零功能 static int a;
* 2、保值作用
* 3、隐藏功能
*/
// 静态变量 保值作用 仅仅创建一次
static NSString *cell_id = @"UITableViewCell";
// 利用重用创建
UITableViewCell *cell = nil;
// 在重用池查找
cell = [tableView dequeueReusableCellWithIdentifier:cell_id];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cell_id];
}
cell.textLabel.text = self.nameArray[indexPath.row];
// indexPath.section 那个分组
// indexPath.row 哪一行
NSString *name = [NSString stringWithFormat:@"%ld.png", indexPath.row + 1];
cell.imageView.image = [UIImage imageNamed:name];
// 显示具体信息 cell 类型用 UITableViewCellStyleSubtitle
cell.detailTextLabel.text = self.numberArray[indexPath.row];
// 右側附件button 枚举类型
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
row 的高度
#pragma mark - 跳转 row 的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 80.0f;
}
返回分组的名字
#pragma mark - 返回分组的名字
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if (section == 0) {
return @"分组一";
}
return @"分组二";
}
设置分组头部
#pragma mark - 设置分组头部
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 50)];
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor redColor];
if (section == 0) {
label.text = @"1组";
} else {
label.text = @"2组";
}
return label;
}
设置分组头部的高度
#pragma mark - 设置分组头部的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 60.0f;
}#pragma mark - 设置分组头部的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 60.0f;
}
cell 的点击事件
#pragma mark - cell 的点击事件
- (void)tableView:(UITableView *) tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// 取消选中状态
[tableView deselectRowAtIndexPath:indexPath animated:YES];
SecondViewController *secondVC = [[SecondViewController alloc] init];
[self.navigationController pushViewController:secondVC animated:YES];
}
实现索引
#pragma mark - 实现索引
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return @[@"1组", @"2组"];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
UI_UITableView_搭建的更多相关文章
- Online Judge(OJ)搭建(第一版)
搭建 OJ 需要的知识(重要性排序): Java SE(Basic Knowledge, String, FileWriter, JavaCompiler, URLClassLoader, Secur ...
- Angular2入门系列教程1-使用Angular-cli搭建Angular2开发环境
一直在学Angular2,百忙之中抽点时间来写个简单的教程. 2016年是前端飞速发展的一年,前端越来越形成了(web component)组件化的编程模式:以前Jquery通吃一切的田园时代一去不复 ...
- 总结:Mac前端开发环境的搭建(配置)
新年新气象,在2016年的第一天,我入手了人生中第一台自己的电脑(大一时好友赠送的电脑在一次无意中烧坏了主板,此后便不断借用别人的或者网站的).macbook air,身上已无分文...接下来半年的房 ...
- Angular企业级开发(5)-项目框架搭建
1.AngularJS Seed项目目录结构 AngularJS官方网站提供了一个angular-phonecat项目,另外一个就是Angular-Seed项目.所以大多数团队会基于Angular-S ...
- 【分享】标准springMVC+mybatis项目maven搭建最精简教程
文章由来:公司有个实习同学需要做毕业设计,不会搭建环境,我就代劳了,顺便分享给刚入门的小伙伴,我是自学的JAVA,所以我懂的.... (大图直接观看显示很模糊,请在图片上点击右键然后在新窗口打开看) ...
- 一起学微软Power BI系列-使用技巧(4)Power BI中国版企业环境搭建和帐号问题
千呼万唤的Power BI中国版终于落地了,相信12月初的微软技术大会之后已经铺天盖地的新闻出现了,不错,Power BI中国版真的来了,但还有些遗憾,国际版的一些重量级服务如power bi emb ...
- 从0开始搭建SQL Server AlwaysOn 第一篇(配置域控)
从0开始搭建SQL Server AlwaysOn 第一篇(配置域控) 第一篇http://www.cnblogs.com/lyhabc/p/4678330.html第二篇http://www.cnb ...
- 从0开始搭建SQL Server AlwaysOn 第二篇(配置故障转移集群)
从0开始搭建SQL Server AlwaysOn 第二篇(配置故障转移集群) 第一篇http://www.cnblogs.com/lyhabc/p/4678330.html第二篇http://www ...
- 从0开始搭建SQL Server AlwaysOn 第三篇(配置AlwaysOn)
从0开始搭建SQL Server AlwaysOn 第三篇(配置AlwaysOn) 第一篇http://www.cnblogs.com/lyhabc/p/4678330.html第二篇http://w ...
随机推荐
- ASP.NET Identity 使用 RoleManager 进行角色管理 (VS2013RC)
注:本文系作者原创,但可随意转载. 最近做一个Web平台系统,系统包含3个角色,“管理员, 企业用户, 评审专家”, 分别有不同的功能.一直以来都是使用微软封装好的Microsoft.AspNet.I ...
- Access-Control-Allow-Origin设置多个域名
Access-Control-Allow-Origin只能返回一个. 所以用以下方法实现多个白名单域名:创建一个数据,获取请求中origin,如果在数组里,就返回该origin,如果不在,就返回一个默 ...
- EOJ-大学生程序设计邀请赛(华东师范大学)-E-黑心啤酒厂
E. 黑心啤酒厂 Time limit per test: 1.0 seconds Time limit all tests: 1.0 seconds Memory limit: 256 megaby ...
- pywordfrom
http://files.cnblogs.com/files/zhang-pengcheng/pywordform-0.02.zip Win8.1自带微软五笔输入法开启方法
- 嵌入式Linux中摄像头使用简要整理【转】
转自:http://www.cnblogs.com/emouse/archive/2013/03/03/2941938.html 本文涉及软硬件平台: 开发板:飞凌OK6410 系统:Ubuntu 1 ...
- eclipse CreateProcess error=87
http://blog.csdn.net/mylove709834360/article/details/9253697 完美解决~
- AC日记——Roma and Poker codeforces 803e
803E - Roma and Poker 思路: 赢或输或者平的序列: 赢和平的差的绝对值不得超过k: 结束时差的绝对值必须为k: 当“?”时可以自己决定为什么状态: 输出最终序列或者NO: dp( ...
- 前端面试知识点锦集(JavaScript篇)
目录 1.谈谈你对Ajax的理解?(概念.特点.作用) 2.说说你对延迟对象deferred的理解? 3.什么是跨域,如何实现跨域访问? 4.为什么要使用模板引擎? 5.JavaScript是一门什么 ...
- 详解xml
xml xml简介 XML是一种可扩展标记语言 (Extensible Markup Language, XML).是一种可扩展的标记语言,XML重在数据交换,用于不同平台或者应用程序之间交换数据,存 ...
- 离别在须臾——AFO
始于 2016-12-25 终于 2017-11-30 一开始就陷入了颓废的坑,然后,直至 2017 年暑假,颓废的气息一发不可收拾, 从 Q_fight 到 aoqi_baitian ,从 大主宰 ...