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?
An IBOutlet is for hooking up a property to a view when designing your XIB. An IBAction is for hooking a method (action) up to a view when designing your XIB. An IBOutlet lets you reference the view from your controller code.
@IBAction is similar to @IBOutlet , but goes the other way: @IBOutlet is a way of connecting code to storyboard layouts, and @IBAction is a way of making storyboard layouts trigger code. This method takes one parameter, called sender . It's of type UIButton because we know that's what will be calling the method.
"Interface Builder". Before Xcode 4, the interface files (XIBs and NIBs) were edited in a separate program called Interface Builder, hence the prefix. IBAction is defined to void , and IBOutlet to nothing. They are just clues to Interface Builder when parsing files to make them available for connections.
There is an easy way to achieve this. Goto your Interface builder of your class >> Select the view u want to add action to >> then change its custom class from IDENTITY INSPECTOR from UIView to 'UIControl'. Now u can add any IBAction method to this view.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With