2010-06-11 11 views

Odpowiedz

241

Oto mój kompletne rozwiązanie, bez wcięcia (0left align) komórki!

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

działa perfekcyjnie, dzięki! –

+1

perfect .... dziękuję. – CKT

+1

dobry + dla miłej pracy – Warewolf

3

Zatrzymuje wcięcie:

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

wychodził podobny problem, gdzie chciałem niestandardowe pola wyboru, aby pojawić się w trybie edycji, ale nie na - przycisk Usuń „()”.

Stefan's answer skierował mnie we właściwym kierunku.

Stworzyłem przycisk przełączania i dodałem go jako edycjęAccessoryView do komórki i podłączyłem do metody.

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

Zastosowane metody te delegat

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

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

Swift 3 równoważne przyjętym odpowiedzi tylko z potrzebnych funcs:

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

func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle { 
    return .none 
} 
Powiązane problemy