Created
March 12, 2018 08:40
-
-
Save serhatsezer/2d248dd3a669470cdae9979c760798e7 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
| 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