<UITableViewDataSource,UITableViewDelegate>

//设置表视图的编辑状态

-(void)setEditing:(BOOL)editing animated:(BOOL)animated

{

[super setEditing:editing animated:animated];

[_tableView setEditing:editing animated:animated];

}

//设置编辑模式(插入、删除、选择),默认是删除

-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath

{

return UITableViewCellEditingStyleInsert;

}

//设置编辑内容(插入、删除

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

{

if(editingStyle==UITableViewCellEditingStyleDelete)

{

//如果是删除的话。。。。

}

if(editingStyle==UITableViewCellEditingStyleInsert){

//将数据加入到数据源

[_dataArray insertObject:@"test" atIndex:indexPath.row];

//更新界面

[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];

}

}

//设置是否允许移动单元格

-(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath

{

return YES;

}

//移动单元格执行的操作第1个参数是操作的表视图对象,第2个参数是单元格原来所在的行,第3个参数是单元格移动后新的行

-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath

{

//修改数据源,将moveRowAtIndexPath所在的数据删除,插入到destinationIndexPath所在的位置上

NSString *str=_dataArray[sourceIndexPath.row];

[_dataArray removeObjectAtIndex:sourceIndexPath.row];

[_dataArray insertObject:str atIndex:destinationIndexPath.row];

}

//当选择一行数据,当表视图处于编辑状态时将其数据添加到删除数组中

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

if(_tableView.editing){

NSString *str=_dataArray[indexPath.row];

if(![_removeArray containsObject:str]){

[_removeArray addObject:str];

}

}

}

//当用户取消选择某行数据时,将该行数据从删除数组中移除

-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath

{

//判断表视图是否处于编辑状态

if(_tableView.editing){

NSString *str=_dataArray[indexPath.row];

if([_removeArray containsObject:str]){

[_removeArray removeObject:str];

}

}

}

//设置编辑模式(选择)

-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath

{

//插入和删除一起设置效果为选择模式

return UITableViewCellEditingStyleInsert|UITableViewCellEditingStyleDelete;

}

//返回分组数,默认是1

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

return 1;

}

//返回cell的个数

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

return _dataArray.count;

}

//设置每个cell的内容

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

static NSString *identifier=@"cell";

UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];

if(cell==nil){

cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];

}

cell.textLabel.text=_dataArray[indexPath.row];

return cell;

}

UI控件之UITableView的协议方法的更多相关文章

  1. UI控件之UIPickerView的协议方法

    UIPickerView:选择视图,父类是UIView UIPickerView *pickerView=[[UIPickerView alloc]initWithFrame:CGRectMake(1 ...

  2. UI控件之UITableView的基本属性

    UITableView:特殊的滚动视图,横向固定,可以在纵向上滚动,自动计算contentSize 创建tableView,初始化时指定样式,默认是plain UITableView *_tableV ...

  3. iOS 使用UI控件的外观协议UIAppearance进行设置默认UI控件样式

    在iOS开发中,经常会对UINavigationBar的样式进行全局样式.采用的设置方式有两种: 第一种,采用方式如下: [UINavigationBar appearance] 这种是对一类对象的默 ...

  4. C#子线程更新UI控件的方法总结

    http://blog.csdn.net/jqncc/article/details/16342121 在winform C/S程序中经常会在子线程中更新控件的情况,桌面程序UI线程是主线程,当试图从 ...

  5. C#学习之在辅助线程中修改UI控件----invoke方法

    Invoke and BeginInvoke 转载地址:http://www.cnblogs.com/worldreason/archive/2008/06/09/1216127.html 在Invo ...

  6. [Android] Android 让UI控件固定于底部的几种方法

    Android 让UI控件固定于底部的几种方法1.采用linearlayout布局:android:layout_height="0dp" <!-- 这里不能设置fill_p ...

  7. Atitit.swt 线程调用ui控件的方法

    Atitit.swt 线程调用ui控件的方法 1 SwingUtilities.invokeLater1 2 display.asyncExec方法1 3  display.timerExec(500 ...

  8. 面试题汇总--数据储存/应用程序/UI控件/客户端的安全性与框架处理。。。

    一 数据储存  1.如果后期需要增加数据库中的字段怎么实现,如果不使用 CoreData 呢?编写 SQL 语句来操作原来表中的字段1)增加表字段ALTER TABLE 表名 ADD COLUMN 字 ...

  9. iOS-UI控件之UITableView(一)

    UITableView 介绍 UITableView 是用来用列表的形式显示数据的UI控件 举例 QQ好友列表 通讯录 iPhone设置列表 tableView 常见属性 // 设置每一行cell的高 ...

随机推荐

  1. uboot下tftp传输文件

    uboot下通过tftp工具传输文件,tftp与ftp是完全不同的工具或协议. 1) 下载并安装程序 sudo apt-get install tftp-hpa tftpd-hpa tftp-hpa是 ...

  2. Servlet Cookie 处理

    Servlet Cookie 处理 Cookie 是存储在客户端计算机上的文本文件,并保留了各种跟踪信息.Java Servlet 显然支持 HTTP Cookie. 识别返回用户包括三个步骤: 服务 ...

  3. Laravel开发:Laravel核心——Ioc服务容器源码解析(服务器解析)

    make解析 服务容器对对象的自动解析是服务容器的核心功能,make 函数.build 函数是实例化对象重要的核心,先大致看一下代码: public function make($abstract) ...

  4. Tomcat设置maxPostSize导致Post请求不过去

    问题:最近部署项目,用到的Tomcat 版本:7.0.82.0,发现一直登陆不了,查询发现原来前端的数据传递不到后端 排查问题:通过debug日志发现,后端没有接受到前端用户的登陆数据,检查发现Tom ...

  5. 错误命令“if not exist "\Dll" mkdir "\Dll" xcopy "\bin\Debug\*.*" "F:\647\VS项目\EtrolMes2014SY\Framework\Dll" /e /i /y”已退出,代码为 9009

    分析错误 第一步:观察错误,发现plugin文件夹中未生成对应的编译文件. 第二步:XCOPY命令无法执行,百度xcopy为何无法执行 第三步,搜索,发现环境变量未配置正确. 就是环境变量path(大 ...

  6. 【BZOJ1976】[BeiJing2010组队]能量魔方 Cube 最小割

    [BZOJ1976][BeiJing2010组队]能量魔方 Cube Description 小C 有一个能量魔方,这个魔方可神奇了,只要按照特定方式,放入不同的 能量水晶,就可以产生巨大的能量. 能 ...

  7. jPage.js分页

    jPage.js插件使用文档 这一款插件主要是为了bootstrap原生的分页功能效果不理想而诞生的一款插件. jPage.js代码更新地址为:https://github.com/leslieSie ...

  8. http-proxy-middleware使用方法和实现原理(源码解读)

    本文主要讲http-proxy-middleware用法和实现原理. 一 简介 http-proxy-middleware用于后台将请求转发给其它服务器. 例如:我们当前主机A为http://loca ...

  9. js验证表单大全1

    附加:js验证radio是否选择 <script language="javascript"> function checkform(obj) { for(i=0;i& ...

  10. 解决Vue的表格中,expand只有某些行需要展开的问题。

    element UI里的表格里,type="expand"的话,所有行都有展开的选项,然而实际中有些行根据判断不需要展开,而element目前对这个问题还不是很友好,现在有个可以通 ...