Created
January 17, 2017 14:22
-
-
Save zonble/3158bc5d03e557b014406778ba589afa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import PlaygroundSupport | |
class SampleTableViewController : UITableViewController { | |
var selectedIndexPath: IndexPath? | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "Cell") | |
} | |
override func numberOfSections(in tableView: UITableView) -> Int { | |
return 1 | |
} | |
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
return 10 | |
} | |
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) | |
cell.textLabel?.text = "\(indexPath.row)" | |
if let selectedIndexPath = selectedIndexPath { | |
cell.accessoryType = indexPath == selectedIndexPath ? .checkmark : .none | |
} | |
return cell | |
} | |
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { | |
self.selectedIndexPath = indexPath | |
tableView.deselectRow(at: indexPath, animated: true) | |
DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) { | |
tableView.reloadData() | |
} | |
} | |
} | |
PlaygroundPage.current.liveView = SampleTableViewController(style: .plain) | |
PlaygroundPage.current.needsIndefiniteExecution = true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment