views:

1149

answers:

4

I have created a blank new view-based application project in Xcode. It generated a myProjectViewController and an nib for it. In that nib for that view controller, there is just one view. I wanted to test some event handling stuff and created an -(IBAction) method that will just log a "hello world" when I touch the view. But for some reason, IB doesn't give me a chance to hook up the action. What am I doing wrong there? I also tried to put a UIView as subview there. When I drag from that to File's Owner (whoose class is the myProjectViewController, where I have the IBAction in the header), doesn't even mention the IBAction. But it actually should, right?

A: 

We have the touchesBegan, touchesMoved and touchesEnded methods for this purpose.

lostInTransit
A: 

IBAction are methods designed to receive an action from a control. They are not an indication to Interface Builder that the method is the source of an action (that the class generates in response to some other events).

To wire up custom events from a UIView subclass, see my answer to a related question here. You will need to use the delegate/protocol approach.

Jason
A: 

Make sure your -(IBAction)someMethod; line is also in your .h file, otherwise Interface Builder won't see it.

willc2
A: 

IBAction is just a tag that you add to a method declaration that identifies that method as a candidate for being connected to a control's action.

An IBAction method is the method that receives the action message of some other control.

UIViews don't send any actions. UIControls do. So there's nothing to hook up from a plain UIView to your object. You can only hook up IBActions to UIControl subclasses and UIBarButtonItems.

Jon Hess