2010-06-11 5 views

risposta

241

Ecco la mia soluzione completa, senza indentazione (align 0left) della cella!

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

funziona perfettamente, grazie! –

+1

perfetto .... grazie. – CKT

+1

buono + per un buon lavoro – Warewolf

3

Ciò arresta rientro:

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

ho affrontato un problema simile in cui ho voluto caselle di controllo personalizzati per apparire in modalità Modifica, ma non il pulsante - cancella '()'.

Stefan's answer mi ha guidato nella direzione corretta.

Ho creato un pulsante di attivazione e l'ho aggiunto come modifica alla vista di accesso alla cella e collegato a un metodo.

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

implementati questi metodi delegato

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

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

Swift 3 equivalente a risposta accettata solo con i funcs necessari:

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

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