短视频app开发,左滑删除或长按弹出删除选择框
短视频app开发,左滑删除或长按弹出删除选择框
一、 左滑删除
- (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
}
}
以上就是 短视频app开发,左滑删除或长按弹出删除选择框,更多内容欢迎关注之后的文章
浙公网安备 33010602011771号