PDA

View Full Version : Fast track to dragging and dropping in Interface Builder: - (IBAction)methodName;


fury
08-20-2008, 01:36 PM
That little ditty just saved me a ton of time and made it a cinch to connect the view in Interface Builder to the controller in Xcode. It wasn't entirely obvious until I saw it in one of the project templates and tried to make sense of it myself.

In other words, place this in your ViewController header file (ViewController.h)

- (IBAction)methodName;

& draw up your method in the implementation (ViewController.m) like so:

- (IBAction)methodName {
doSomething;
}

Save the header and implementation files, then open the respective XIB file. Right-click on a button, slider, or whatever to bring up the list of events it catches (e.g. for buttons, the default is Touch Up Inside). Drag from the circle on the right over to File's Owner in the XIB folder window. It should bring up another little window in which you can select the action you just made. Then whenever that action is performed on the control, your action code will be performed. Also found that right-click-dragging straight from the control in question over to File's Owner will pick that control's most likely desired default event. Note: File's Owner should expect to be set to an instance of your specific ViewController, otherwise it won't know what actions you've made possible in your code. This is how it's set up by default if you pick one of the template applications like Flipside, etc.; but otherwise, you can make sure of it by going to the right-most tab on Inspector, and at the top, give it an appropriate class name to expect.

That was the missing link for me when I tried playing with the earlier betas of the SDK - I couldn't quite figure out how to drag and drop to link things up, and this just saved me a ton of time on a concept UI that I whipped up real quick.

Sorry I don't have screenshots to show at the moment, the computer it's on isn't connected to the net

chrismmm
12-03-2008, 02:52 PM
have u found an appl or are u developing one that will allow power users to drag and drop files...tired of hearing about sftp..know how to do that and its not effective

fury
12-10-2008, 01:19 AM
That's a different subject entirely. I was referring here to the ability to make logical connections from your interface (and the buttons and such; the events that occur on them) to your code in the iPhone SDK by dragging and dropping with Interface Builder. It's a little bit of info that wasn't too obvious to me when I started to learn the SDK so I thought I'd post it here for anyone else looking around the same way I was before the light bulb switched on. (That, and keep a memory for myself, since I don't actually have a genuine Mac of my own to develop on)