// // TableView.swift // SelectableCell // // Created by Samet Dede on 01/06/16. // Copyright © 2016 Samet DEDE. All rights reserved. // import UIKit class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { var selectedCells:[Int] = [] override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } //MARK: TableView func numberOfSectionsInTableView(tableView: UITableView) -> Int { return 1 } func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 10 } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) cell.textLabel?.text = "\(indexPath.row + 1). Cell" cell.accessoryType = self.selectedCells.contains(indexPath.row) ? .Checkmark : .None return cell } func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { if self.selectedCells.contains(indexPath.row) { self.selectedCells.removeAtIndex(self.selectedCells.indexOf(indexPath.row)!) } else { self.selectedCells.append(indexPath.row) } tableView.reloadData() } }