Skip to content

Commit 1740839

Browse files
committed
Added Reset To Defaults button 🔴
1 parent e024f8e commit 1740839

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

‎TableViewDemoUsingCocoaBindings/Base.lproj/Main.storyboard

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,17 @@
799799
<action selector="removeTableRow:" target="XfG-lQ-9wD" id="t2a-db-lWr"/>
800800
</connections>
801801
</button>
802+
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="R7z-Qv-uT5">
803+
<rect key="frame" x="339" y="-7" width="147" height="32"/>
804+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
805+
<buttonCell key="cell" type="push" title="Reset To Defaults" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="sDq-nO-OY0">
806+
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
807+
<font key="font" metaFont="system"/>
808+
</buttonCell>
809+
<connections>
810+
<action selector="resetToDefaultsBtnClicked:" target="XfG-lQ-9wD" id="IUd-fA-1MD"/>
811+
</connections>
812+
</button>
802813
</subviews>
803814
</view>
804815
<connections>

‎TableViewDemoUsingCocoaBindings/ViewController.swift

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ class ViewController: NSViewController, NSTableViewDataSource, NSTableViewDelega
4040
}
4141
}
4242

43+
override func controlTextDidEndEditing(_ obj: Notification) {
44+
saveDreams()
45+
}
46+
4347
func numberOfRows(in tableView: NSTableView) -> Int {
4448
return dreams.count
4549
}
@@ -70,10 +74,6 @@ class ViewController: NSViewController, NSTableViewDataSource, NSTableViewDelega
7074
saveDreams()
7175
}
7276

73-
override func controlTextDidEndEditing(_ obj: Notification) {
74-
saveDreams()
75-
}
76-
7777
@IBAction func addTableRow(_ sender: Any) {
7878
addNewDream()
7979
}
@@ -82,8 +82,15 @@ class ViewController: NSViewController, NSTableViewDataSource, NSTableViewDelega
8282
removeDream()
8383
}
8484

85+
86+
@IBAction func resetToDefaultsBtnClicked(_ sender: Any) {
87+
dreamNames = ["Climb Mount Everest", "Swim in the Atlantic"]
88+
dreams = dreamNames.map{Dream(name: $0)}
89+
table.reloadData()
90+
saveDreams()
91+
}
92+
8593
func saveDreams() {
8694
defaults[.dreams] = dreams.map({ $0.name })
8795
}
8896
}
89-

0 commit comments

Comments
 (0)