UI控件之UITableView的协议方法
<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的协议方法的更多相关文章
- UI控件之UIPickerView的协议方法
UIPickerView:选择视图,父类是UIView UIPickerView *pickerView=[[UIPickerView alloc]initWithFrame:CGRectMake(1 ...
- UI控件之UITableView的基本属性
UITableView:特殊的滚动视图,横向固定,可以在纵向上滚动,自动计算contentSize 创建tableView,初始化时指定样式,默认是plain UITableView *_tableV ...
- iOS 使用UI控件的外观协议UIAppearance进行设置默认UI控件样式
在iOS开发中,经常会对UINavigationBar的样式进行全局样式.采用的设置方式有两种: 第一种,采用方式如下: [UINavigationBar appearance] 这种是对一类对象的默 ...
- C#子线程更新UI控件的方法总结
http://blog.csdn.net/jqncc/article/details/16342121 在winform C/S程序中经常会在子线程中更新控件的情况,桌面程序UI线程是主线程,当试图从 ...
- C#学习之在辅助线程中修改UI控件----invoke方法
Invoke and BeginInvoke 转载地址:http://www.cnblogs.com/worldreason/archive/2008/06/09/1216127.html 在Invo ...
- [Android] Android 让UI控件固定于底部的几种方法
Android 让UI控件固定于底部的几种方法1.采用linearlayout布局:android:layout_height="0dp" <!-- 这里不能设置fill_p ...
- Atitit.swt 线程调用ui控件的方法
Atitit.swt 线程调用ui控件的方法 1 SwingUtilities.invokeLater1 2 display.asyncExec方法1 3 display.timerExec(500 ...
- 面试题汇总--数据储存/应用程序/UI控件/客户端的安全性与框架处理。。。
一 数据储存 1.如果后期需要增加数据库中的字段怎么实现,如果不使用 CoreData 呢?编写 SQL 语句来操作原来表中的字段1)增加表字段ALTER TABLE 表名 ADD COLUMN 字 ...
- iOS-UI控件之UITableView(一)
UITableView 介绍 UITableView 是用来用列表的形式显示数据的UI控件 举例 QQ好友列表 通讯录 iPhone设置列表 tableView 常见属性 // 设置每一行cell的高 ...
随机推荐
- 22lvs 健康节点检查
[root@lb03 scripts]# cat lvm_health_check.sh #!/bin/bash web_ip=( 10.0.0.17 10.0.0.18 ) # 检查恢复就添加节点 ...
- 关于fork()父子进程返回值的问题
我们都知道,父进程fork()之后返回值为子进程的pid号,而子进程fork()之后的返回值为0.那么,现在就有一个问题了,子进程fork()的返回值是怎么来的?如果子进程又执行了一遍fork()函数 ...
- java 获取网页指定内容-2(实践+修改)
import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; ...
- 集合Map映射(使用xml文件)
Hibernate允许我们将Map元素与RDBMS进行映射. 我们知道,List和Map是基于索引的集合. 在map的情况下,索引列作为键,元素列用作值. 使用xml文件在集合映射中映射Map的示例 ...
- Spring MVC下拉选项(Select)
以下示例显示如何在使用Spring Web MVC框架的表单中使用下拉选项(Dropdown).首先使用Eclipse IDE来创建一个WEB工程,实现一个让用户可选择自己所在的国家的功能.并按照以下 ...
- git Staging Deleted files
Use git rm foo to stage the file for deletion. (This will also delete the file from the file system, ...
- 安装Oracle后修改IP总结(转载)
转载自:http://blog.csdn.net/bleibo/article/details/5447198 安装Oracle后修改IP总结(转载) 针对ORACLE 10G 在安装完后,修改IP ...
- 从 ie10浏览器下Symbol 未定义的问题 探索vue项目如何兼容ie低版本浏览器(ie9, ie10, ie 11 )
问题: vue项目在ie11下一片空白并报Symbol 未定义的错 原因: ie10浏览器解析不了es6的语法,需要我们使用babel(Babel是一种工具链,主要用于将ECMAScr ...
- CMake error:System Error:No such file or directory CMake error:Could not open file for write in copy operation xxxx.ros_Config.cmake.tmp.
微型电脑或嵌入式与电脑还是有点不同的,在微型电脑上ros indigo 版本下利用catkin编译如果你遇到如下错误: CMake error:System Error:No such file or ...
- Linux命令之split
split用来将大文件分割成小文件.有时文件越来越大,传送这些文件时,首先将其分割可能更容易. 使用vi或其他工具诸如sort时,如果文件对于工作缓冲区太大,也会存在一些问题. 因此有时没有选择余地, ...