2010-06-11 5 views

Répondre

241

Voici ma solution complète, sans indentation (alignement 0left) de la cellule!

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

fonctionne parfaitement, merci! –

+1

parfait .... merci. – CKT

+1

bon + pour un beau travail – Warewolf

3

Cela arrête indentation:

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

je fait face à un problème similaire où je voulais apparaître des cases à cocher personnalisées en mode d'édition, mais pas « (-) » bouton supprimer.

Stefan's answer m'a dirigé dans le bon sens.

J'ai créé un bouton bascule et l'ai ajouté en tant qu'éditerAccessoryView à la cellule et l'ai câblé à une méthode.

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

Mis en œuvre ces méthodes de délégué

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

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

Swift 3 équivalent à réponse acceptée avec seulement les funcs nécessaires:

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

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