0

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!

Konrad Kolasa
  • 621
  • 1
  • 8
  • 22
  • 1
    maybe `@interface MyViewController: UIViewController `? –  Sep 02 '12 at 11:48
  • Are you asking: How to write a delegate? If yes, you may find this answer useful: http://stackoverflow.com/questions/626898/how-do-i-create-delegates-in-objective-c – hol Sep 02 '12 at 11:50

1 Answers1

2

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. UIControlEventValueChanged would be a suitable event for your needs.

jrturton
  • 118,105
  • 32
  • 252
  • 268
  • Ohh, really, thanks! So my idea seems now really weird :P I just didn't think to look into UIControl reference. I managed it with [self sendActionsForControlEvents:UIControlEventValueChanged]; – Konrad Kolasa Sep 02 '12 at 12:29