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的高 ...
随机推荐
- Linux HugePage特性
Linux HugePage特性 HugePage,就是指的大页内存管理方式.与传统的4kb的普通页管理方式相比,HugePage为管理大内存(8GB以上)更为高效.本文描述了什么是HugePage, ...
- tonymillion/Reachability的使用
tonymillion/Reachability是GitHub上的一个开源工具类,目測是依据Apple的Reachability Demo改写而成. 该类能够測试到某一网络.主机等的可达性,支持Blo ...
- Unity3D学习笔记——IDE菜单栏
一:菜单栏: 1.File: 2.Edit: 3.Assets: 4.GameObject: 5.Component: 6.Window: 7.Help:
- cookie细节
设置cookie时,不像设置session,可以马上生效,它的生效时间是下一次请求页面.
- EasyUI怎么利用onBeforeRender事件
onBeforeRender事件是view的属性,该事件发生在把ajax请求到的数据填充到表格内容中之前 将此段代码附加在DataGrid初始化后执行,即可完成在DataGrid渲染之前进行操作 // ...
- 【转】10 个MySQL数据库备份教程推荐
10 个MySQL数据库备份教程推荐 MySQL是动态网站开发中最著名的开源数据库系统.如果你在网站中使用了MySQL,那么你应该定期备份你的数据以防止它丢失. 本文将介绍自动或手动备份MySQL数据 ...
- HTML学习笔记——常用元素及其属性(二)
一.HTML表单 -- form标签 -- 与浏览者交互 1.form 标签 -- 代表HTML表单 form标签是成对出现的,以<form>开始,以</form>结束 属性. ...
- 如何用SQL为每一行均产生一个随机数
) as int) as RndId from 表名
- 让vs只启动自己想调试的站点
VS中里面多个WEB项目如何只启动一个? 每次启动时,右下角都会出现一堆的 网站有10来个.即使设置了默认启动项目, 但每次按F5启动,或者哪怕是在项目上右键启动新实例 右下角都会出现这一堆的站点 有 ...
- 使用QFileInfo类获取文件信息(在NTFS文件系统上,出于性能考虑,文件的所有权和权限检查在默认情况下是被禁用的,通过qt_ntfs_permission_lookup开启和操作。absolutePath()必须查询文件系统。而path()函数,可以直接作用于文件名本身,所以,path() 函数的运行会更快)
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/Amnes1a/article/details/65444966QFileInfo类为我们提供了系统无 ...