cocoa - making a UIImageView class act like a UIButton

Posted by Mike on Stack Overflow See other posts from Stack Overflow or by Mike
Published on 2010-03-30T23:17:03Z Indexed on 2010/03/30 23:53 UTC
Read the original article Hit count: 515

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 for any help!

© Stack Overflow or respective owner

Related posts about cocoa

Related posts about iphone