简单tableView的使用
UITableView是一个用于显示列表的视图,可以作为子视图镶嵌在主视图上,可以滑动,选取各种参数
定义:
@interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>{
@property (nonatomic, retain) NSArray *dataList;
@property (nonatomic, retain) UITableView *myTableView;
UITableView *tableView = [[UITableViewalloc] initWithFrame:FRAME_TABLEVIEWstyle:UITableViewStylePlain];
注意:这里的两个属性 dataList和myTableView并不要求实现,只需要在头文件定义就可以了
Delegate必须要有,因为必须要实现它的接口
使用:
//init tableView
NSArray *list = [NSArray arrayWithObjects:@"模糊",@"素描",@"怀旧", nil];
self.dataList = list;
// 设置tableView的数据源
tableView.dataSource = self;
// 设置tableView的委托
tableView.delegate = self;
// 设置tableView的背景图
// tableView.backgroundView = [[UIImageView alloc] init];
self.myTableView = tableView;
self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.view addSubview:self.myTableView];
常用的属性设置:
//设置转置,使table view倒过来
);
//取消滑动出现删除
tableView.showsVerticalScrollIndicator = NO;
接口的实现:
//set cells
//定义每个列表项的属性
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellWithIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellWithIdentifier];
if (cell == nil) {
cell = [[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellWithIdentifier];
}
cell.imageView.image = [UIImageimageNamed:@"example.png"];
return cell;
}
//set number of sections
//定义块的个数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
;
}
//行首缩进
//定义首行缩进的宽度
- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath
{
;
}
//row height
//定义每一行的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
// if ([indexPath row] % 2 == 0) {
// cell.backgroundColor = [UIColor blueColor];
// } else {
// cell.backgroundColor = [UIColor greenColor];
// }
}
//select rows callback
//选择某行以后的动作方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
switch ([indexPath row]) {
:
testFilter = [[GPUImageFastBlurFilteralloc] init];
break;
:
testFilter = [[GPUImageSketchFilteralloc] init];
break;
:
testFilter = [[GPUImageSepiaFilteralloc] init];
break;
default:
break;
}
}
// delete
//选择删除以后的方法
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"执行删除操作");
}
//设置没有分界线
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
returnUITableViewCellEditingStyleNone;
}
//number of rows
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
returnself.dataList.count;
}
简单tableView的使用的更多相关文章
- Masonry学习分享
不完整目录 •UIScrollView 应用Masonry的正确用法 •tableHeaderView使用Masonry •同向文字显示优先级 1.基础篇 1.1基础使用 1.1.1运行效果 1.1. ...
- iOS面试考察点
)自我介绍.项目经历.专业知识.自由提问 (2)准备简历.投发简历.笔试(电话面试.).面试.复试.终面试.试用.转正.发展.跳槽(加薪升职) 1闲聊 a)自我介绍:自我认识能力 b)评价上一家公司: ...
- IOS xib在tableview上的简单应用(通过xib自定义cell)
UITableView是一种常用的UI控件,在实际开发中,由于原生api的局限,自定义UITableViewCell十分重要,自定义cell可以通过代码,也可以通过xib. 这篇随笔介绍的是通过xib ...
- 简单天气应用开发——自定义TableView
顺利解析JSON数据后,天气数据已经可以随意提取了,现在要做的就是建立一个简单的UI. 实况信息较为简单,几个Lable就可以解决.主要是七天天气预报有点麻烦,那是一个由七个字典构成的数组,需要提取出 ...
- IOS中TableView的使用(1) -创建一个简单的tableView
创建一个简单的tableView: #import <UIKit/UIKit.h> /*tableView 一定要遵守这两个协议: UITableViewDataSource,UITabl ...
- 【转】ios tableView那些事(一)创建一个简单的tableView
工作也有半年多了!几乎每个项目中的会用到tableview这个神奇而好用的控件,在学习和工作中都会看别人的博客!对我有很大的帮助,就如同站在巨人的肩膀上的感觉吧 哈哈!于是决定重新开始写博客,希望能帮 ...
- 简单的TableView
背景知识 每个表都是UITableView的实例,表中的每一行都是UITableViewCell的实例. TableView的种类 Grouped table Plain table without ...
- tableView简单的动画效果
tableView 中一些动画效果通常都是实现willDisplayCell的方法来展示出一些动画的效果 (1).带有3D效果的小型动态展示 -(void)tableView:(UITableView ...
- 关于tableView的简单实例
关于tableCell选中颜色 //无色 cell.selectionStyle = UITableViewCellSelectionStyleNone; //蓝色 cell.selectionSty ...
随机推荐
- 计算机网络-ip地址聚合后可用的地址数
(1)59.81.1.128/28=59.81.1.1000-0000(2)59.81.1.144/28=59.81.1.1001-0000(3)59.81.1.160/28=59.81.1.1010 ...
- SQL Execute语法.
一,执行字符串: EXECUTE语句可以执行存放SQL语句的字符串变量,或直接执行SQL语句字符串. 语法:EXECUTE({@字符串变量|[N]’SQL语句字符串’}[+...n]) 例子:Decl ...
- Python编写相关注意事项
1.# -*- coding: utf-8 -*-代码首部添加这个,不然会报Non_ASCII charater错误 python闭包:实际应用场景1.保持闭包运行完后的环境: 2.根据外部作用域的局 ...
- Angularjs总结(三)摸态框的使用
静态页面: <input class="btn btnStyle " value="提 取" type="button" ng-cli ...
- SQL,学习基础2
列=字段, 记录=实体 事物日志文件(用来记录数据库的增删情况,扩展名LDF) 数据库文件(但是只有一个是主数据库文件(即用它来启动的),其余为次数据库文件)mdf 数据类型: 整形(整数)——in ...
- Android 学习手札(三) 视图(View)
在Android 系统红,任何可视化组件都需要从android.view.View类继承.可以使用两种方式创建View对象. · 一种方式是使用XML来配置View的相关属性,然后使用相应的方法来装载 ...
- win8 + ubuntu14.04 安装步骤
一.首先,从硬盘上划分一个空闲分区(推荐最少20G,每个人也可以按照自己的需要自行设定).记住各个分区的容量,方便安装时辨认.并从Ubuntu官方网站上下载Ubuntu 14.04 LTS 光盘镜像. ...
- JS-运动框架
写这段代码,是因为之前看过某前RD写过,但在测试过程中发现有不完美的地方. 问题在于判断运动停止条件这里,对于之前停止的判断太片面,只能判断一个条件值时的情况,对于多条件时,会发现运动后的各项值并未达 ...
- PHPCMS标签:PC标签模板语法规则
模板语法规则1.变量表示{$name} 被解析成 <?=$name?>,表示显示变量$name的值,其中的“name”由英文字母.数字和下划线组成首字母必须是英文字母或者下划线. 2.常量 ...
- ASP.NET 后台不识别ASPX中的控件
请问后台不识别ASPX中的控件,怎么解决 这个程序是在网上下载的 C# code <asp:DataGrid runat="server" ID="dgList1& ...