项目介绍:
自定义拖拽TableView
-
自定义拖拽TableView 使用方法模拟系统的方法,在网上也看了下别人的实现,总觉得不太通用,于是自己封装了一个相对公用一点的,喜欢的话留下你的星星
-
github:https://github.com/caixiang305621856/CXDragTableView
#pragma mark - CXDragableCellTableViewDataSource
//更新数据源(多个分组的情况可自己处理)
- (void)tableView:(UITableView *)tableView newMoveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath {
[self.dataSource exchangeObjectAtIndex:sourceIndexPath.row withObjectAtIndex:destinationIndexPath.row];
}
#pragma mark - CXDragableCellTableViewDelegate
//指定不能拖拽的cell
- (BOOL)tableView:(CXDragTableView *)tableView newCanMoveRowAtIndexPath:(NSIndexPath *)indexPath {
NSInteger row = indexPath.row;
if (row == 0) {
return NO;
} else{
return YES;
}
return NO;
}
//指定拖拽的跨度
- (BOOL)tableView:(CXDragTableView *)tableView newTargetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath {
if (sourceIndexPath.section == proposedDestinationIndexPath.section && (proposedDestinationIndexPath.row != 0)) {
return YES;
}else{
return NO;
}
}
//开始拖拽
- (void)tableView:(CXDragTableView *)tableView willMoveCellAtIndexPath:(NSIndexPath *)indexPath processCell:(UITableViewCell *)cell {
[(FTQuestionOptionCell *)cell drawdragCell];
}
//拖拽松手后
- (void)tableView:(CXDragTableView *)tableView endMoveCellAtIndexPath:(NSIndexPath *)indexPath processCell:(UITableViewCell *)cell {
[(FTQuestionOptionCell *)cell resetDrawdragCell];
}