2010-06-11 16 views

Respuesta

241

Aquí está mi solución completa, sin sangría (align 0left) de la célula!

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

funciona perfectamente, gracias! –

+1

perfecto .... gracias. – CKT

+1

bueno uno + por buen trabajo – Warewolf

3

Esto detiene la sangría:

- (BOOL)tableView:(UITableView *)tableview shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath { 
    return NO; 
} 
2

que se enfrentó a un problema similar donde quería casillas de verificación personalizados para que aparezcan en el modo de edición, pero no el botón - delete '()'.

Stefan's answer me condujeron en la dirección correcta.

Creé un botón de alternar y lo agregué como un accesorio de edición de edición a la Celda y lo conecté a un método.

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

implementadas estos métodos de delegado

- (BOOL)tableView:(UITableView *)tableview shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath { 
    return NO; 
} 

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { 
    return UITableViewCellEditingStyleNone; 
} 
29

Swift 3 equivalente a respuesta aceptada con sólo los funcs necesarios:

func tableView(_ tableView: UITableView, shouldIndentWhileEditingRowAt indexPath: IndexPath) -> Bool { 
    return false 
} 

func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle { 
    return .none 
} 
Cuestiones relacionadas