How to select multiple rows in UITableView in edit mode?

user4809833 picture user4809833 · Nov 28, 2015 · Viewed 21.3k times · Source

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

Answer

Leo picture Leo · Nov 28, 2015

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