Как реализовать простое удаление (с красной кнопкой минус) в UITableViewCell - PullRequest
0 голосов
/ 25 мая 2011

Я удаляю ячейку из табличного представления, и она реализует удаление пальцем, используя следующий код:

#pragma mark -   
#pragma mark Table View Data Source Methods

- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{ 
[super setEditing:editing animated:animated]; 
[addTagTableView setEditing:editing animated:YES];
}

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

 //Updating the data-model array and deleting the row
- (void)tableView:(UITableView *)tv commitEditingStyle:    (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{
    // If row is deleted, remove it from the list. 
    if (editingStyle == UITableViewCellEditingStyleDelete) 
    {
            [self.tagsArray removeObjectAtIndex:indexPath.row];
        [self.addTagTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }
}

Это позволяет мне реализовать удаление, но я хочу просто удалить минус красную кнопку, как этого добиться?

Ответы [ 2 ]

7 голосов
/ 25 мая 2011
- (void)viewDidLoad {
    self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

С этим кодом в вашем приложении есть кнопка редактирования.Если вы нажмете эту кнопку, «красный минус» появится автоматически:)

3 голосов
/ 25 мая 2011

Вы можете установить UIButton и подключить его к IBAction. В IBAction напишите, чтобы вы могли сделать согласно вашему требованию.

 -(IBAction)editTableForDeletingRow
 {
      [addTagTableView setEditing:editing animated:YES];
 }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...