UITTableView滑动删除
2016-06-28 20:07
405 查看
代码:
#pragma mark-tableView的删除代理方法
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return
YES;
}
//返回编辑类型
- (UITableViewCellEditingStyle )tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath
*)indexPath
{
return
UITableViewCellEditingStyleDelete;
}
//编辑操作
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle ==
UITableViewCellEditingStyleDelete)
{
//删除行
//1.删除数据源
//2.界面上删除cell
teleModel *model =
self.datasources[indexPath.row];
//数据删除
[[DatabaseManager
sharedManager]deleModel:model];
[self.datasources
removeObjectAtIndex:indexPath.row];
//直接刷新表格,没有动画
[tableView reloadData];
}
}
#pragma mark-tableView的删除代理方法
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return
YES;
}
//返回编辑类型
- (UITableViewCellEditingStyle )tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath
*)indexPath
{
return
UITableViewCellEditingStyleDelete;
}
//编辑操作
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle ==
UITableViewCellEditingStyleDelete)
{
//删除行
//1.删除数据源
//2.界面上删除cell
teleModel *model =
self.datasources[indexPath.row];
//数据删除
[[DatabaseManager
sharedManager]deleModel:model];
[self.datasources
removeObjectAtIndex:indexPath.row];
//直接刷新表格,没有动画
[tableView reloadData];
}
}
相关文章推荐
- APUE环境配置
- UE4 Smart_Pointer_Library
- android quick settings中去掉不需要的图标
- 日常坑-Illegal connection port value '3306'
- 设计模式---Builder模式
- ueditor 简单/复杂工具栏切换
- UI布局--四种布局
- 【J2EE】org.hibernate.exception.SQLGrammarException: could not execute query错误
- build 时候把场景加进去的时候,场景有对应的序号
- 设置UITextField的内容
- NGUI 指定视口大小
- iOS开发 UITabBar角标 红点形式 (tabBarItem.badgeValue)
- burpsuite1.6安装使用方法详解
- String、StringBuffer、StringBuilder之间的区别
- UISearchBar 设置背景色,去掉黑线
- 使用手势对UIImageView进行缩放、旋转和移动
- UGUI代码添加带参数的Button事件
- PostgreSQL:“ FATAL: requested WAL segment00800002A0 has already been removed”
- iOS上直接缩小UIImageView的大小会产生锯齿,可以先将其缩放后再使用.
- [IOS]UIKit控件使用总结