views:

690

answers:

2

That's tricky. I have a small button over a very big one. When the small button on that big button is pressed, the small button does something. But the big one does nothing. Of course. But now I want that the big button also does something, no matter if the small button was tapped or not. So the small button has to forward all touch events to that big button. What would be the easiest way to do it?

I know for UIView, but UIControl's have their very own touch handling methods different from those of UIView. In UIView that could look somewhat like this:

[self.nextResponder touchesBegan:touches withEvent:event];
+1  A: 

you can implement a protocol to let the big button receive messages from the small button, Though what i would do is have both buttons in a UIViewController, have the small button tell teh UIViewController that it was clicked (either through selector or protocol) and then the UIViewController can update the big button accordingly....more on protocols here http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocProtocols.html

Daniel
+1  A: 

Might want to take a look at this post that shows ways to synthesize touch events. It stopped working for a while, though. Revisiting it just now it looks like he's updated it for 3.0 support so it might work for you. A caveat is that it might not be legit for a shipping app.

An easier way is to break out the method that does the work (let's call it bigButtonWork) when the big button gets tapped and make it public. Then the big button tap handler just calls this routine. When the small button gets tapped you can choose inside its handler to do its own thing or call bigButtonWork instead.

But I'm guessing you want it to simulate the big button actually getting pushed (complete with highlights and state changes) so you may have to go the synthesized event route.

Ramin