iOS tableview系統(tǒng)左滑刪除 左滑置頂 自定義左滑事件功能 輸入框彈出
或者
//tableView自帶的左滑刪除
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
// 定義編輯樣式
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleDelete;
}
// 進(jìn)入編輯模式村斟,按下出現(xiàn)的編輯按鈕后,進(jìn)行刪除操作
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
//较幌。。蹂窖。猜年。抡锈。。
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
// 修改編輯按鈕文字
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
return @"刪除";
}
//iOS11解決UITableView側(cè)滑刪除無限拉伸的方法
- (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)){
if (@available(iOS 11.0, *)) {
UIContextualAction *deleteAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"刪除" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
//乔外。床三。。杨幼。撇簿。聂渊。
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
// 這句很重要,退出編輯模式四瘫,隱藏左滑菜單
[tableView setEditing:NO animated:YES];
completionHandler(true);
}];
UISwipeActionsConfiguration *actions = [UISwipeActionsConfiguration configurationWithActions:@[deleteAction]];
// 禁止側(cè)滑無線拉伸
actions.performsFirstActionWithFullSwipe = NO;
return actions;
}else{
return nil;
}
}