Skip to content

Commit b75b965

Browse files
Add toggle of cell accessoryType
1 parent 901bc18 commit b75b965

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed
2.25 KB
Binary file not shown.

Checkroutine/Checkroutine/Base.lproj/Main.storyboard

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<rect key="frame" x="0.0" y="0.0" width="335" height="43.5"/>
2727
<autoresizingMask key="autoresizingMask"/>
2828
<subviews>
29-
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="1Nz-gK-sE3">
29+
<label opaque="NO" userInteractionEnabled="NO" tag="100" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="1Nz-gK-sE3">
3030
<rect key="frame" x="24" y="11" width="295" height="22"/>
3131
<fontDescription key="fontDescription" type="system" pointSize="17"/>
3232
<nil key="textColor"/>

Checkroutine/Checkroutine/CheckRoutineTableViewController.swift

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,48 @@ class CheckRoutineTableViewController: UITableViewController {
2222

2323

2424
// MARK: - CheckRoutineTableViewController UITableViewDelegate Methods
25-
25+
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
26+
27+
// Toggles cell accessoryType from checkmark to none
28+
// Maybe refactor and have a custom accessoryType
29+
if let cell = tableView.cellForRow(at: indexPath) {
30+
if cell.accessoryType == .checkmark{
31+
cell.accessoryType = .none
32+
}else {
33+
cell.accessoryType = .checkmark
34+
}
35+
}
36+
37+
tableView.deselectRow(at: indexPath, animated: true)
38+
}
2639

2740

2841
// MARK: - CheckRoutineTableViewController UITableViewDataSource Methods
2942

3043
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
3144

32-
return 1
45+
return 5
3346
}
3447

3548
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
3649

3750
let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "CheckroutineItem", for: indexPath)
3851

39-
return cell
52+
let label = cell.viewWithTag(100) as! UILabel
53+
54+
if indexPath.row == 0 {
55+
label.text = "I am the man"
56+
}else if indexPath.row == 1 {
57+
label.text = "Who provides"
58+
}else if indexPath.row == 2{
59+
label.text = "CAN you see me?"
60+
}
61+
62+
63+
64+
return cell
4065
}
4166

4267
}
43-
//
44-
//extension CheckRoutineTableViewController: UITableViewDelegate{
45-
//
46-
//
47-
//}
48-
//
49-
//extension CheckRoutineTableViewController: UITableViewDataSource{
50-
//
51-
//
52-
//}
68+
5369

0 commit comments

Comments
 (0)