I'm making a preference bundle where the specifiers are loaded from a .plist
file. Some of the specifiers are UISwitches
. How can I have a function called when the value of one of the UISwitches
is changed?
-
This might help you : http://stackoverflow.com/questions/23986150/uiswitch-doesnt-change-state – Yuyutsu Dec 26 '14 at 18:50
-
go through this : http://stackoverflow.com/questions/11847059/objective-c-writing-uiswitch-state-in-a-plist-for-a-key?answertab=active#tab-top – Yuyutsu Dec 26 '14 at 18:58
2 Answers
To detect when changes to a preference value occur, apps can also register for the notification
NSUserDefaultsDidChangeNotification
. The shared NSUserDefaults object sends this notification to your app whenever it detects a change to a preference located in one of the persistent domains. You can use this notification to respond to changes that might impact your user interface. For example, you could use it to detect changes to the user’s preferred language and update your app content appropriately.
Register for this notification. When you receive it, check whether the switch has changed. Unfortunately, the notification doesn't tell you what change triggered it.

- 65,323
- 19
- 161
- 287
UISwitch
es are UIControl
s so you can receive actions from them just like UIButtons
.

- 34,548
- 4
- 48
- 69
-
I added an action to the switch in the .plist, but the action executes when the switch's cell is tapped, and not when the switch itself is toggled. – KyleCool1 Dec 26 '14 at 19:01
-
See that one http://stackoverflow.com/questions/4098653/iphone-sdk-detecting-a-change-in-uiswitch – Jean-Baptiste Yunès Dec 26 '14 at 19:54