tableView上的侧滑删除功能
2016-03-31 14:44
204 查看
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return
YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath
*)indexPath
{
if (editingStyle ==UITableViewCellEditingStyleDelete) {
[self.listArrayremoveObjectAtIndex:indexPath.row];//删除数据源当前行数据
[tableView deleteRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationNone];
}
}
//如果想在侧拉的时候显示是中文的删除,只需要用下面的方法替换掉上面的方法就好了
-(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewRowAction *deleteRoWAction = [UITableViewRowAction
rowActionWithStyle:UITableViewRowActionStyleDestructive
title:@"删除"
handler:^(UITableViewRowAction *action,
NSIndexPath *indexPath){//title可自已定义
NSLog(@"点击删除");
NSDictionary *dic =
@{@"userToken":[[NSUserDefaults
standardUserDefaults] objectForKey:@"userToken"],
@"receivingAddressId":[self.addressArray[indexPath.row]
id]};
[[NetworkSingleton
sharedManager] postResultWithParameter:dic
url:IDelReceivingAddress
successBlock:^(id responseBody) {
} failureBlock:^(NSString *error) {
IALog(@"%@",error);
} showHUD:YES];
[self.addressArray
removeObjectAtIndex:indexPath.row];//删除数据源当前行数据
[tableView deleteRowsAtIndexPaths:@[indexPath]
withRowAnimation:UITableViewRowAnimationNone];
}];
return @[deleteRoWAction];
}
{
return
YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath
*)indexPath
{
if (editingStyle ==UITableViewCellEditingStyleDelete) {
[self.listArrayremoveObjectAtIndex:indexPath.row];//删除数据源当前行数据
[tableView deleteRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationNone];
}
}
//如果想在侧拉的时候显示是中文的删除,只需要用下面的方法替换掉上面的方法就好了
-(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewRowAction *deleteRoWAction = [UITableViewRowAction
rowActionWithStyle:UITableViewRowActionStyleDestructive
title:@"删除"
handler:^(UITableViewRowAction *action,
NSIndexPath *indexPath){//title可自已定义
NSLog(@"点击删除");
NSDictionary *dic =
@{@"userToken":[[NSUserDefaults
standardUserDefaults] objectForKey:@"userToken"],
@"receivingAddressId":[self.addressArray[indexPath.row]
id]};
[[NetworkSingleton
sharedManager] postResultWithParameter:dic
url:IDelReceivingAddress
successBlock:^(id responseBody) {
} failureBlock:^(NSString *error) {
IALog(@"%@",error);
} showHUD:YES];
[self.addressArray
removeObjectAtIndex:indexPath.row];//删除数据源当前行数据
[tableView deleteRowsAtIndexPaths:@[indexPath]
withRowAnimation:UITableViewRowAnimationNone];
}];
return @[deleteRoWAction];
}
相关文章推荐
- Jedis存储Java对象--Java序列化为byte数组方式
- ios 浮点数精度问题
- Lintcode—跳跃游戏
- 苹果开发者账号的种类
- CSS3 选择器——伪类选择器
- 网站克隆神器
- TabLayout选择位置
- php csrf防御
- Posix multi-thread programming 笔记
- 2016-3-31 笔记
- 进程管理
- MFC中用OpenCV库显示视频
- Struts2 - <s:property name="">
- C++异常以及错误处理
- Storm分布式实时流计算框架相关技术总结
- storm实战入门一
- PopupWindow的使用
- 身份证号码 出生年月 以及有效校验位 正则表达式判断
- 网址资源,个人整理来之不易请珍惜,页面有点乱,请谅解。
- iOS6、7、8、9新特性汇总和适配说明