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的使用的更多相关文章

  1. Masonry学习分享

    不完整目录 •UIScrollView 应用Masonry的正确用法 •tableHeaderView使用Masonry •同向文字显示优先级 1.基础篇 1.1基础使用 1.1.1运行效果 1.1. ...

  2. iOS面试考察点

    )自我介绍.项目经历.专业知识.自由提问 (2)准备简历.投发简历.笔试(电话面试.).面试.复试.终面试.试用.转正.发展.跳槽(加薪升职) 1闲聊 a)自我介绍:自我认识能力 b)评价上一家公司: ...

  3. IOS xib在tableview上的简单应用(通过xib自定义cell)

    UITableView是一种常用的UI控件,在实际开发中,由于原生api的局限,自定义UITableViewCell十分重要,自定义cell可以通过代码,也可以通过xib. 这篇随笔介绍的是通过xib ...

  4. 简单天气应用开发——自定义TableView

    顺利解析JSON数据后,天气数据已经可以随意提取了,现在要做的就是建立一个简单的UI. 实况信息较为简单,几个Lable就可以解决.主要是七天天气预报有点麻烦,那是一个由七个字典构成的数组,需要提取出 ...

  5. IOS中TableView的使用(1) -创建一个简单的tableView

    创建一个简单的tableView: #import <UIKit/UIKit.h> /*tableView 一定要遵守这两个协议: UITableViewDataSource,UITabl ...

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

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

  7. 简单的TableView

    背景知识 每个表都是UITableView的实例,表中的每一行都是UITableViewCell的实例. TableView的种类 Grouped table Plain table without ...

  8. tableView简单的动画效果

    tableView 中一些动画效果通常都是实现willDisplayCell的方法来展示出一些动画的效果 (1).带有3D效果的小型动态展示 -(void)tableView:(UITableView ...

  9. 关于tableView的简单实例

    关于tableCell选中颜色 //无色 cell.selectionStyle = UITableViewCellSelectionStyleNone; //蓝色 cell.selectionSty ...

随机推荐

  1. 使用本地光盘安装Microsoft .NET Framework 3.5 for Win8/WinServer2012

    如何使用本地源安装Microsoft .NET Framework 3.5 作为SQL Server 2012的 必要组件,校验组件过程有个小BUG,即使没有安装也通过,但会卡在安装环节(enabli ...

  2. YII 数据库相关操作

    CDbConnection: 一个抽象数据库连接CDbCommand: SQL statementCDbDataReader: 匹配结果集的一行记录CDbTransaction:数据库事务 访问数据库 ...

  3. new作为修饰符

    new 修饰符与 new 操作符是两个概念 new 修饰符用于声明类或类的成员,表示隐藏了基类中同名的成员.而new 操作符用于实例化一个类型 new 修饰符只能用于继承类,一般用于弥补基类设计的不足 ...

  4. Python: 设计模式 之 工厂模式例(1)

    #!/usr/bin/env python #coding=utf-8 # # 工厂模式一例 # 版权所有 2014 yao_yu (http://blog.csdn.net/yao_yu_126) ...

  5. WPF布局容器综合展示

    Border控件,以及几个重要要的属性:Background:背景的 Brush 对象BorderBrush:用来绘制边框BorderThickness: Border 边框的宽度,设置边框每一边的线 ...

  6. PHP之路——Redis安装

    windows: redis下载链接:https://github.com/ServiceStack/redis-windows 然后编辑redis.windows.conf文件,我看网上有的教程说编 ...

  7. WCF X.b 操作引用了已经从 Y.b 操作导出的消息元素 [http://tempuri.org/:b]。可以通过更改方法名称或使用 OperationContractAttribute 的 Name 属性更改其中一个操作的名称...

    详细错误如下: 很可能由 IncludeExceptionDetailInFaults=true 创建的 ExceptionDetail,其值为: System.InvalidOperationExc ...

  8. [原创]dm642_HPI调通并boot成功

    一直在折腾前段时间画好的dm642+lpc4357板子,说明下这个板子的结构: 主芯片为DM642,这个片子很老了,但因为对这个片子熟悉,别折腾 没有给DM642加FLASH,配了一片LPC4357, ...

  9. Codeforces Round #207 (Div. 2)

    A:超级大水题: 代码: #include<cstdio> #define maxn 105 using namespace std; int n,a[maxn],x,y,ans; int ...

  10. Alice's Chance

    poj1698:http://poj.org/problem?id=1698 题意:爱丽丝要拍电影,有n部电影,规定爱丽丝每部电影在每个礼拜只有固定的几天可以拍电影,只可以拍前面w个礼拜,并且这部电影 ...