- 左滑删除
-
- - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
- return YES;
- }
- - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
- if (editingStyle == UITableViewCellEditingStyleDelete) {
- [dataArray removeObjectAtIndex:indexPath.row];
- // Delete the row from the data source.
- [testTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
- }
- else if (editingStyle == UITableViewCellEditingStyleInsert) {
- // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
- }
- }
- - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{
- return @"下载";
- }
长按手势
- 添加1秒手势
- UILongPressGestureRecognizer * longPressGr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressToDo:)];
- longPressGr.minimumPressDuration = 1.0;
- [self.tableView addGestureRecognizer:longPressGr];
- [longPressGr release];
响应长按事件打印行:
- -(void)longPressToDo:(UILongPressGestureRecognizer *)gesture
- {
- if(gesture.state == UIGestureRecognizerStateBegan)
- {
- CGPoint point = [gesture locationInView:self.tableView];
- NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:point];
- NSlog(@"%d",indexPath.row);
- if(indexPath == nil) return ;
- //add your code here
- }
- }