Есть ли способ скрыть кнопку "-" (Удалить) во время редактирования UITableView
В моем приложении iphone у меня есть UITableView в режиме редактирования, где пользователю разрешено только переупорядочивать строки, разрешение на удаление отсутствует.
Итак, есть ли способ, которым я могу скрыть красную кнопку от TableView. Пожалуйста, дайте мне знать.
Спасибо
Ответы
Ответ 1
Вот мое полное решение, без отступа (выравнивание по левому краю) ячейки!
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewCellEditingStyleNone;
}
- (BOOL)tableView:(UITableView *)tableview shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
return NO;
}
- (BOOL)tableView:(UITableView *)tableview canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
Ответ 2
Swift 3 эквивалентен принятому ответу с помощью только необходимых функций:
func tableView(_ tableView: UITableView, shouldIndentWhileEditingRowAt indexPath: IndexPath) -> Bool {
return false
}
func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
return .none
}
Ответ 3
Это останавливает отступ:
- (BOOL)tableView:(UITableView *)tableview shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
return NO;
}
Ответ 4
У меня возникла аналогичная проблема, когда я хотел, чтобы пользовательские флажки появлялись в режиме редактирования, но не кнопку "(-)" delete.
Ответ Стефана помог мне в правильном направлении.
Я создал кнопку переключения и добавила ее как editAccessoryView в ячейку и связала ее с методом.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
....
// Configure the cell...
UIButton *checkBoxButton = [[UIButton alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 40.0f, 32.0f)];
[checkBoxButton setTitle:@"O" forState:UIControlStateNormal];
[checkBoxButton setTitle:@"√" forState:UIControlStateSelected];
[checkBoxButton addTarget:self action:@selector(checkBoxButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
cell.editingAccessoryType = UITableViewCellAccessoryCheckmark;
cell.editingAccessoryView = checkBoxButton;
return cell;
}
- (void)checkBoxButtonPressed:(UIButton *)sender {
sender.selected = !sender.selected;
}
Реализованы эти методы делегатов
- (BOOL)tableView:(UITableView *)tableview shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
return NO;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleNone;
}