0

I am making a table view and can display cells already. My table view has a navigation bar with an "edit" button.

I am looking for a way to add a "delete all" button and when this button is tapped, check boxes will display in front of every cell.

Could anyone guide me in swift 2.0?

Tobi Nary
  • 4,566
  • 4
  • 30
  • 50
  • 2
    Try doing it by yourself first. Take a look at [this](http://stackoverflow.com/questions/29117759/how-to-create-radio-buttons-and-checkbox-in-swift-ios) post. – António Ribeiro Feb 23 '16 at 07:55

2 Answers2

0

I can now solve my issue. By overriding below function, I can detect edit mode and display the button.

    override func setEditing(editing: Bool, animated: Bool) {
        if (editing) {
            super.setEditing(true, animated: true)
            self.navigationItem.rightBarButtonItem = self.rightBarButtonItem
        } else {
            super.setEditing(false, animated: true)
            self.navigationItem.rightBarButtonItem = nil
        }
    }
-1

Try checking this in git hub or stackoverflow exaples where you can change the table view edit style, where check boxes can be created

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

-(BOOL) tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath

if change in data is required for edit you might need to change the other delegates with below conditional check for an example

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if([tableView isEditing] == YES) {
return x_number;
}
return y_number;
}

If you are looking for delete all button in edit mode, then try creating a new UIViewController in seague where you create this check box and table view, when delete all button is clicked

mkumar
  • 111
  • 1
  • 10
  • Hello. The question is tagged "swift", please provide an answer in Swift, not in another language. Thanks! – Eric Aya Feb 26 '16 at 13:19