ios 实现在tableViewCell上面添加长按手势 删除该条cell以及列表后台数据等
2016-12-23 17:39
591 查看
自己的代码 需要 把属性更改成自己要使用的
//创建长按手势
在cellForRowAtIndexPath代理方法中
UILongPressGestureRecognizer *longPressGR = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(lpGR:)];
//设定最小的长按时间 按不够这个时间不响应手势
longPressGR.minimumPressDuration = 1;
[cell addGestureRecognizer:longPressGR];
//实现手势对应的功能
-(void)lpGR:(UILongPressGestureRecognizer *)lpGR
{
if (lpGR.state == UIGestureRecognizerStateBegan) {//手势开始
CGPoint point = [lpGR locationInView:self.tbFirst];
self.index = [self.tbFirst indexPathForRowAtPoint:point]; // 可以获取我们在哪个cell上长按
self.indexNum = self.index.row;
}
if (lpGR.state == UIGestureRecognizerStateEnded)//手势结束
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"是否删除" message:nil delegate:self cancelButtonTitle:@"确认" otherButtonTitles:@"取消", nil];
[alert show];
}
}
//提示框代理方法
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {
NSDictionary * dic = self.hopeDs[self.indexNum];
NSString *url = [NSString stringWithFormat:@"%@%@",JJBaseUrl,@"/v1/infomarket/delPost"];
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"postId"] = dic[@"id"];
params[@"ticket"] = [JJUserInfoModel userInfoFromFile].ticket;
[JJHttpTools deleteUrl:url params:params success:^(id json) {
[JJMBProgressTool showSuccessProgressViewWithText:@"已删除"];
[self.hopeDs removeObjectAtIndex:self.indexNum];
//删除列表内容
[self.tbFirst deleteRowsAtIndexPaths:[NSArray arrayWithObject:self.index] withRowAnimation:UITableViewRowAnimationFade];
} failure:^(NSError *error) {
}];
}else{
}
}
//创建长按手势
在cellForRowAtIndexPath代理方法中
UILongPressGestureRecognizer *longPressGR = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(lpGR:)];
//设定最小的长按时间 按不够这个时间不响应手势
longPressGR.minimumPressDuration = 1;
[cell addGestureRecognizer:longPressGR];
//实现手势对应的功能
-(void)lpGR:(UILongPressGestureRecognizer *)lpGR
{
if (lpGR.state == UIGestureRecognizerStateBegan) {//手势开始
CGPoint point = [lpGR locationInView:self.tbFirst];
self.index = [self.tbFirst indexPathForRowAtPoint:point]; // 可以获取我们在哪个cell上长按
self.indexNum = self.index.row;
}
if (lpGR.state == UIGestureRecognizerStateEnded)//手势结束
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"是否删除" message:nil delegate:self cancelButtonTitle:@"确认" otherButtonTitles:@"取消", nil];
[alert show];
}
}
//提示框代理方法
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {
NSDictionary * dic = self.hopeDs[self.indexNum];
NSString *url = [NSString stringWithFormat:@"%@%@",JJBaseUrl,@"/v1/infomarket/delPost"];
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"postId"] = dic[@"id"];
params[@"ticket"] = [JJUserInfoModel userInfoFromFile].ticket;
[JJHttpTools deleteUrl:url params:params success:^(id json) {
[JJMBProgressTool showSuccessProgressViewWithText:@"已删除"];
[self.hopeDs removeObjectAtIndex:self.indexNum];
//删除列表内容
[self.tbFirst deleteRowsAtIndexPaths:[NSArray arrayWithObject:self.index] withRowAnimation:UITableViewRowAnimationFade];
} failure:^(NSError *error) {
}];
}else{
}
}
相关文章推荐
- IOS 列表删除数据,添加数据,列表排序实现
- 【iOS开发-76】Private Contacts案例:导航控制器使用、数据传递、第三方类库使用、tableViewCell的添加删除、数据存储等
- 一个iOS图片选择器的DEMO(实现图片添加,宫格排列,图片长按删除,以及图片替换等功能)
- 在fragment里面添加list列表,然后实现跳转(以及数据传递)
- IOS学习之——Cell的添加、删除以及移动
- UIday1002:UITableView 2 用UITableView实现通讯录cell简单的数据移动、删除、添加功能
- Jquery 实现动态添加table tr 和删除tr 以及checkbox的全选 和 获取添加TR删除TR后的数据
- ios tableview cell上面的view添加手势,两个手指同时点击cell上的view的冲突(手势冲突)
- iOS UITableView中CELL添加计时器实现自动删除的问题
- 第十二章:表视图常用UI范例——实现折叠列表,以及cell增加滑动手势
- IOS菜鸟的所感所思(四)——自定义UICollectionViewCell以及网络数据的添加。
- 一个iOS图片选择器的DEMO(实现图片添加,宫格排列,图片长按删除,以及图片替换等功能)
- 【原创】TreeView控件实现拖拉、添加以及删除结点操作类库
- 稳扎稳打Silverlight(57) - 4.0通信之WCF RIA Services: 概述, 通过 DomainDataSource 实现数据的添加、查询、更新和删除操作
- 用Nhibernate怎么实现数据的添加、删除、修改简单程序
- PHP简单系统数据添加以及数据删除模块源文件下载
- C# 对sharepoint 列表的一些基本操作,包括添加/删除/查询/上传文件给sharepoint list添加数据
- JS调用C#后台代码---JS实现DataGrid“全选”、“反选”、调用后台代码批量删除数据
- 稳扎稳打Silverlight(57) - 4.0通信之WCF RIA Services: 概述, 通过 DomainDataSource 实现数据的添加、查询、更新和删除操作
- ListView listCtrl 不能显示和不能正确添加行数据以及列表题不能显示问题