cocoa - making a class like UIButton
- by Mike
For some reason that will take too much time to explain, I have to create a UIImageView based class that has some properties of a button.
Imagine a class like the UISwitch (no I cannot base my class on the UISwitch) with two states, on and off. WHen the user selects one state, it runs a method like a button that was clicked and the method receives the sender id.
I have already the class more or less working. The class is based on UIImageView. I am having difficulties to understand the following.
WHen I create a new button I have a line that is like
[myButton addTarget:self action:NSSelectorFromString(myMethod)
forControlEvents:UIControlEventTouchUpInside];
This line defines a target and an action to run when the button is triggered.
I my case I would need something like
[myObject addTarget:self action:myMethod ifState:1]
//or another thing ifState:2
I have no idea what kind of code I should put on the class to make this work.
Remember that as a button the class should send the "sender" information to identify the object which triggered the action...
Can you guys, transcendental gurus help?
thanks.