Управление переупорядочением в UITableView
Я разрабатываю игру, в которой я использую UITableView
, у которого есть пользовательский сотовый (UItableViewCell
подкласс).
В режиме редактирования:
Должно показаться только управление переупорядочиванием UITableView
.
Сейчас я получаю элемент delete и reordering.
Как получить только управление переупорядочением во время редактирования?
Ответы
Ответ 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;
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{
}
Ответ 2
Спасибо, много оксигена это сработало....
Я писал это в
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView1 dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
cell.showsReorderControl = YES; // to show reordering control
return cell;
}
но я напишу метод, который вы указали
Спасибо тонны
Ответ 3
Вы должны использовать этот метод для скрытия кнопки удаления.
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleNone;
}
Ответ 4
tableView.showsReorderControl = YES; // to show reordering control
Чтобы избавиться от контроля удаления, в UITableViewDelegate добавьте
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleNone;
}
Ответ 5
Swift 5.0
Если вы хотите отключить все другие параметры редактирования для ваших ячеек tableView, кроме той, которая позволяет вам изменить их порядок, просто реализуйте эти методы из UITableViewDelegate:
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}
// Removes the ability to delete current cell
func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
return UITableViewCellEditingStyle.none
}
func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
return true
}