Skip to content

Instantly share code, notes, and snippets.

@serhatsezer
Created March 12, 2018 08:40
Show Gist options
  • Save serhatsezer/2d248dd3a669470cdae9979c760798e7 to your computer and use it in GitHub Desktop.
Save serhatsezer/2d248dd3a669470cdae9979c760798e7 to your computer and use it in GitHub Desktop.
var selectedSection1: [Int: Bool] = [:]
var selectedSection2: [Int: Bool] = [:]
var selectedSection3: [Int: Bool] = [:]
var selectedSection4: [Int: Bool] = [:]
var sections = [selectedSection1, selectedSection2, selectedSection3, selectedSection4]
extension ViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// Array'den ilgili sectionu çıkartıyoruz.
let sectionDict = sections[indexPath.section]
sectionDict[indexPath.row] = true
}
func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
let sectionDict = sections[indexPath.section]
sectionDict[indexPath.row] = false
}
}
extension ViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.checkBox.isSelected = sections[indexPath.section][indexPath.row]
return cell
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment