I’m writing own switch class. I’d like to add a delegate to it – examplary if we have UIImagePickerController we add UIImagePickerControllerDelegate to @interface of some viewcontroller and we can set methods like imagePickerControllerDidCancel:(UIImagePickerController *)picker…
I want to do something similar for my class – it’s named HSwitch, so I want to add HSwitchDelegate to @interface of some view controller.
I would like to add to this delegate a method valueWasChanged, that I could set in viewController and which would be called each time when slider changes value.
How can I do that? I didn’t do it yet, so… please help me 🙂
Thanks!
If your class is a switch, presumably it inherits from UIControl. If this is the case, don’t introduce the complexity of delegates – use target-action instead, and send actions / register targets as you would with any other control. See the UIControl class reference for details.
UIControlEventValueChangedwould be a suitable event for your needs.