UITableView表格视图、UITableView代理方法及应用
一、基本知识点
tableview.separatorStyle = UITableViewCellSeparatorStyleSingleLine;//分割线样式
tableview.delegate = self;
tableview.tableFooterView = [[UIView alloc]init];//去掉线
return 1;//设置table组数,默认是1,因此当只有一个分组时可省略
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
// if (section == 0) {
// return 2;
// }else if (section == 1) {
// return 6;
// }
return 5;//设置每行的行数
}
//设置每行对应的cell
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{//indexPath包含了第几组:indexPath.section 和第几行:indexPath.row
static NSString *identifier = @"cell";//重用机制标识
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];//根据重用标识,找到重用池着对应的cell
if (cell == nil) {
cell.imageView.image = [UIImage imageNamed:@"2.jpg"];
}
return cell;
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UITableView *_tableview = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
_tableview.delegate = self;
_tableview.dataSource = self;
//_tableview.rowHeight = 80;//设置行高
//_tableview.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
[self.view addSubview:_tableview];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 8;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (section == 0) {
return 4;
}else if (section == 2) {
return 2;
}
return 40;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//static NSString *ident = @"cell";//会导致重用机制有bug
NSString *ident = [NSString stringWithFormat:@"%zi,%zi",indexPath.section,indexPath.row];//解决重用机制bug可用这种方法//给每行设置不同的标识
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ident];
// static int num;
// NSLog(@"%d",num++);
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ident];
//cell.textLabel.text = nil;//先清理,再使用
}
cell.textLabel.text = [NSString stringWithFormat:@"%zi组,%zi行",indexPath.section,indexPath.row];
cell.detailTextLabel.text = @"详细信息";
if (indexPath.section == 0 && indexPath.row == 0) {
cell.imageView.image = [UIImage imageNamed:@"1.jpg"];
}
if (indexPath.section == 2 && indexPath.row == 0) {
cell.imageView.image = [UIImage imageNamed:@"2.jpg"];
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;//提示用户可点,点击之后跳至下级界面
//cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;//提示用户可点,点击按钮(叹号)会有相关提示弹出,点击cell之后跳至下级界面
//cell.accessoryType = UITableViewCellAccessoryCheckmark;//对勾
//cell.accessoryType = UITableViewCellAccessoryDetailButton;//提示用户可点,点击按钮(叹号)会有相关提示弹出
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
//每组顶部视图的高度
return 20;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
//自定义每组头视图
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 200, 40 )];
view.backgroundColor = [UIColor redColor];
return view;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
//自定义尾部视图
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 200, 80)];
view.backgroundColor = [UIColor greenColor];
return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 30;
}
//-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
// //设置每行的高度
// if (indexPath.row = 0) {
// return 80;
// }
// return 40;
UITableView表格视图、UITableView代理方法及应用的更多相关文章
- iOS:UITableView表格视图控件
UITableView:表格视图控件,继承滚动视图控件UIScrollView,(类似于UIPickerView选择器,它主要通过设置数据源代理和行为代理实现协议来设置单元格) 对表格的操作主要 ...
- iOS:分组的表格视图UITableView,可以折叠和展开
虽然表格视图可以分组,但是如果分组后,每一行的内容太多,往后翻看起来比较的麻烦.为了解决这个麻烦,可以将分组的行折叠和展开.折叠时,行内容就会隐藏起来:展开时,行内容就会显示出来. 折叠时: 展开后: ...
- iOS:带主标题、副标题、图像类型的表格视图UITableView
制作一个通讯录,包括姓名.电话.头像,将表格视图类型设置为UITableViewCellStyleSubtitle 效果图: //创建一个联系人的类,初始化数据 在视图控制器中实现表格内容的显示 #i ...
- [Xcode 实际操作]五、使用表格-(7)UITableView单元格间隔背景色
目录:[Swift]Xcode实际操作 本文将演示如何给表格设置间隔的背景颜色. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] import UIKit //首先 ...
- [Xcode 实际操作]五、使用表格-(6)UITableView滑动到指定单元格
目录:[Swift]Xcode实际操作 本文将演示如何使表格滑动到指定的索引路径. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] import UIKit //首 ...
- UITableView表视图以及重建机制
表视图UITableView 表视图UITableView,是IOS中最重要的视图,随处可见 表视图通常用来管理一组具有相同数据结构的数据 UITableView继承自UIScrollView,所 ...
- UITableView的全部属性、方法以及代理方法执行顺序,看过之后肯定有收获---董鑫
UITableView-------表视图--继承UIScrollView并遵守NSCoding协议 属性 frame-------------设置控件的位置和大小 backgroundColor-- ...
- UITableView的常用属性和代理方法
以下是近期总结的关于tableView的一些属性和代理方法,以及一些常见的问题,现汇总如下,今后还会持续更新,请继续关注: tableView 的头部和尾部视图属性: UISwitch *foot ...
- IOS UITableView的代理方法详解
一.UITableViewDataSourc(数据源代理) 1.必须实现的回调方法 返回每个分区的行数 - (NSInteger)tableView:(UITableView *)tableView ...
随机推荐
- cocos2d中的可见性检测
游戏的在进行一次渲染的时候,通常会提交大量的渲染对象给gpu.在这些需要渲染的对象中,并不是所有对象都会出现镜头中,即有一部分对象是不可见的. 通常有两种方式来完成不可见对象的剔除工作: (1)直接交 ...
- JavaScript 面向对象与原型
ECMAScript有两种开发模式:1.函数式(过程化);2.面向对象(OOP); 一 创建对象1.普通的创建对象 ? 1 2 3 4 5 6 7 8 9 // 创建一个对象,然后给这个对象新的属性和 ...
- Fliwer:监控植物状态 实现远程浇水
Fliwer是一款针对植物而研发出来的设备,可以监控土壤水分.光照.温度.空气湿度和肥料是否充足这些指标.结合云端的植物数据和天气预报,它能够自动决定什么时候给植物浇水,甚至提醒你什么时候应该施肥.修 ...
- 如何对具有端点加密功能的LINE进行取证
LINE又有新动作了,这回默认即启用了端点加密功能,强调确保传输过程的安全,且让我们来看看如何对付新版的LINE. 有启用Letter Sealing就会在昵称前多个锁头的图像. 这手机据犯嫌供称,落 ...
- MySQL主从同步的延迟原理
1. MySQL数据库主从同步延迟原理. 答:谈到MySQL数据库主从同步延迟原理,得从mysql的数据库主从复制原理说起,mysql的主从复制都是单线程的操作,主库对所有DDL和DML产生binlo ...
- Oracle 查询库中所有表名、字段名、字段名说明,查询表的数据条数、表名、中文表名、
查询所有表名:select t.table_name from user_tables t;查询所有字段名:select t.column_name from user_col_comments t; ...
- WPS项目编号问题
问题:文档需要编号如下: 1.(标题1) 1.1(标题2) 1.1.1(标题3) 1.2 1.2.1 2.(标题1) 2.1(标题2) 2.1.1(标题3) 2.2 2.2.1 方法一: 第一步,打开 ...
- ca des key crt scr
openssl genrsa -des3 -out domain.key 1024 openssl req -new -key domain.key -out domain.csr openssl r ...
- Appium学习路-打包apk和ipa篇
间隔这么长时间再去写Appium的学习篇是有原因的,因为在想要用appium测试ios时,发现appium只能测试debug版本的ipa包.然后就需要自己去学习打包了啊.然后就对xcode各种不了解, ...
- oracle常用操作指令
1.cmd sqlplus /nolog; 2.conn sys/ as sysdba; 3.create user query identified by query;//创建用户 4.al ...