22

I am developing a game in which I am using a UITableView which has custom cell (UItableViewCell subclass).

In editing mode: Only the reordering control of the UITableView should show.

Right now I am getting the delete and the reordering control.

How to get only reordering control while editing ?

djromero
  • 19,551
  • 4
  • 71
  • 68

5 Answers5

65

I know this answer might be late, but I'm putting it just for people who still need it. Just implement the following methods:

- (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{

}
Community
  • 1
  • 1
Mousa
  • 2,926
  • 1
  • 27
  • 35
  • still nothing - I have 2 kinds of UITableViewCell in one UITableView. Printing data works smoothly, but in no way I can manage to show rearranging control :/ – raistlin Nov 19 '12 at 22:22
4

thanks a lot oxigen it worked .... i was writing this in

- (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;
}

but i dint write the method which you have given

Thanks a tons

Laszlo
  • 2,803
  • 2
  • 28
  • 33
Sneha
  • 1,444
  • 15
  • 24
4

You should use this method for hiding delete button.

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    return UITableViewCellEditingStyleNone;
}
Dinesh Raja
  • 8,501
  • 5
  • 42
  • 81
lomec
  • 1,356
  • 1
  • 11
  • 10
2

Swift 5.0

If you want to disable all other editing options for your tableView's cells except the one that allows you to reorder them then just implement those methods from UITableViewDelegate:

func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
    true
}

// Removes the ability to delete current cell
func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle {
    .none
}

func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
    true
}
Nikolay Suvandzhiev
  • 8,465
  • 6
  • 41
  • 47
Bartosz Kunat
  • 1,485
  • 1
  • 23
  • 23
1
 tableView.showsReorderControl = YES; // to show reordering control

To dissmiss delete control, in your UITableViewDelegate add

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleNone;
}
itsji10dra
  • 4,603
  • 3
  • 39
  • 59
oxigen
  • 6,263
  • 3
  • 28
  • 37