17

I want to ask, how can I forward to edit mode, where I can to select multiple rows, as in Messages app, when you click on top right button "Select", when you can choose multiple messages by tapping on circles.

Like this:

enter image description here

I searched a lot, really, but couldn't find anything. Can anyone help me? Some advices

3 Answers3

50

Set

tableView.allowsMultipleSelectionDuringEditing = true

Screenshot

Demo code

class TableviewController:UITableViewController{
    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.allowsMultipleSelectionDuringEditing = true
        tableView.setEditing(true, animated: false)
    }
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)
        cell.textLabel?.text = "\(indexPath.row)"
        return cell
    }
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 10
    }
}
Leo
  • 24,596
  • 11
  • 71
  • 92
8

If you're using Storyboards do this:

enter image description here

Islam
  • 3,654
  • 3
  • 30
  • 40
3
NSMutableArray *selected;

decleare it in you viewcontroller.h file..

selected =[[NSMutableArray alloc]init];
for (int i=0; i<[YOUR_ARRAY count]; i++) // Number of Rows count
        {
            [selected addObject:@"NO"];
        }

add same number of "NO" in selected array using above code for that you had to replace YOUR_ARRAY with your data array that you show in table.

    if(![[selected objectAtIndex:indexPath.row] isEqualToString:@"NO"])
{

    cell.accessoryType=UITableViewCellAccessoryCheckmark;

}

else
{
    cell.accessoryType=UITableViewCellAccessoryNone;
}

put above code in your -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)path {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:path];


if (cell.accessoryType == UITableViewCellAccessoryNone) {
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
    [selected replaceObjectAtIndex:path.row withObject:@"YES"];
} else {
    cell.accessoryType = UITableViewCellAccessoryNone;
    [selected replaceObjectAtIndex:path.row withObject:@"NO"];
}

}

also put this to work correctly..

ash999
  • 106
  • 1
  • 4