Connecting interface builder to the code in Xcode 4 - macos

I created a new project in Xcode 4 using the "Cocoa Application" template and added a few UI elements as seen below:
Now that I've designed this basic interface I'm at a loss for how to actually respond to user events for that button. What type of class should I create and how do I connect that class to IB?
I realize I could read the 100s of pages of Apple documentation that explains all this, but those tend to be too verbose and slightly overwhelming. Thanks for your guidance!

You Ctrl+Drag connections from your controls to actions (defined in code) of the other objects in your XIB file. Cocoa is a powerful framework and Xcode is a wonderful tool, but you're going to have to do some reading to get started. Here's a good site for beginners: Cocoa Dev Central. I recommend you study the tutorials in this order:
Learn Objective-C
Learn Cocoa
Learn Cocoa II
Objective-C Style I
Objective-C Style II
Then you can do some of the more advanced ones. The tutorials are designed for Xcode 3, but they should not be hard to follow, and it you run into problems, Google is your friend.

Control drag from each UI element to the assistant editor.
If you select outlet then it will generate the property and the ivar along with the proper memory management in the .m.
If you select action then it will create a method that will be called when your UI element is interacted with.
I would post a decent picture but I do not have enough reputation...

Related

Xcode 6 - Swift - Multiple views on a single-window storyboard cocoa app

Just last week I decided to dive into the world of Swift and Xcode development, and as of yesterday I am actively working on a new application. I have a lot of experience with Java Swing, but working with that is obviously a lot different than working with Apple's fancy interface builders and storyboards.
I am trying to develop a single-window application that has many different views that can be navigated by buttons. I tried to wrap my head around the way the storyboard works, but even after all my reading of the documentation I don't know really what I'm doing - I'm so used to working in hard code. It came to the point where I wrote my app's entire network layer just to avoid working with the interface.
Basically I have a set of different NSViewControllers, each with references to a few of their components (buttons, labels, etc) and I want certain buttons to be able to change the current view controller (preferably with a segue animation) to a different one. How can I approach this? I would guess that this isn't hard to achieve, but I am lost. Any help would be appreciated!
Let me know if I need to submit any code - I do have the basic classes written but nothing relating to this.
Thanks,
-Aidan

Handling UI in Xamarin.IOS

I am a new iphone developer using xamarin studios.I wanted to know if i need to learn objective-c for handling the ui in xcode?
For example,i have made a UIView(subview) in my viewcontroller(.xib) and i need to generate many such similar UIViews on same button click.
So do I need to write the event code in xcode .h or .m file or in the .cs file in xamarin studios?
No, you do not need to learn Obj-C. It's helpful to be able to READ it, because Apple's samples and docs (as well as a lot of reference material on the web) are written in Obj-C. But you can create your UI using XCode's design tools or directly in code with C# without having to write any Obj-C code.
The views can be created in xib using interface builder or by code using c#, for the event you have to do it in cs file like in csharp.
No, the Objective-C .h/m. files that Xamarin Studio generates in the Xcode project are just stubs mirroring the actions and outlets on your exported C# classes, so that Xcode UI designer (which only understands Obj-C) can connect to them. You can add outlets/actions to these stubs using Xcode's control-drag connections system, and those will be synced back to C#, but anything more advanced added to the obj-c stubs will be ignored. You must write your actual implementations in C#.
You don't need to learn Objective-C, although it will be helpful. It's more important to be familiar with the Cocoa Touch frameworks, particularly UIKit; this knowledge is no less useful when developing with Xamarin.

Safari Web Inspector-esque functionality in Xcode?

Just starting out in Objective-C, so I'm curious as to how some apps that I enjoy function interface-wise. I've cloned a few apps from Github into Xcode, and I'm looking for something similar to Safari's Web Inspector where I can highlight portions of the application and see what piece of code they refer to?
I think it may have something to do with Interface Builder, but I'm not sure where to begin... help?
Thanks!
This doesn't exist AFAIK. Interface Builder doesn't show a representation of your code, it allows to you to lay out (serialized) interface elements to your app graphically.

Where do I find the "Collapsible Panel" Cocoa control in Interface Builder?

I'm trying to add a collapsible panel to a panel I added in the Interface Builder, similar to the one found in Office 2008 and XCode itself.
This is the collapsible panel for those that don't know it:
OS X collapsible panel http://grab.by/3Hqv
Any idea how I can add this to my project? Google hasn't been of much help.
This is most often referred to as a "disclosure view" or "disclosure panel" and usually has to come with an intelligent container view (that grows/shrinks/scrolls correctly with multiple disclosure subviews). There is no such control as part of the API. Most developers roll their own while some use third-party open source.
The Omni Frameworks have one such control that works very well (including "tear-off" panels, etc., if I recall correctly). The drawback: it's a large framework and has a lot of other stuff in it as well.
InspectorKit is another. It's more focused (just the control itself and an IB plugin), but the last incarnation I tested did have a few UI issues with the Interface Builder plugin.
I've also written a framework for handling this: SFBInspectors

How do you test your Cocoa GUIs?

I would like to write some tests for the GUI of my Cocoa program.
Is there any good GUI testing framework for Cocoa apps? The only thing I found is Squish, which, at 2.400€, is well beyond my budget…
Any ideas? How do you test your Cocoa GUIs?
It depends on what you mean by "testing Cocoa GUIs."
If you want tools like the old Virtual User tool included with MPW, then those are few & far between; you'll be looking at tools like Squish and Eggplant.
If you want to write unit tests for your application's human interface, I suggest you follow a "trust, but verify" approach where you trust that as long as you're making the right connections (according to your framework) that your user can interact properly with your framework. That means you can do the majority of your testing by verifying your model and controller code are hooked up to your views correctly.
On my weblog, I've written a couple of examples of how to do this specifically with Cocoa, one for testing user interfaces built with target-action, and one for testing user interfaces built with Cocoa bindings. (Remember, of course, that the two technologies aren't exclusive: If you want to do drag & drop in a table view managed via Cocoa bindings, you'd also have a data source and probably a delegate hooked up via target-action.)
The thing I don't write unit tests for — generally — is the positioning or type of controls in their superview. Sometimes that is important to get and keep correct, however; in that case, I can just query the appropriate properties of the controls and verify them using the standard assertions.
What I virtually never do is write code to "simulate events." The closest I've ever come to that is constructing a fake drag info object and passing that to an outline view data source to ensure it will deal with drags correctly.
I would suggest you take a look at Google's Toolbox for Macintosh. It has, among some other nice goodies, a very nice set of state and rendering test additions for NSView and CALayers. In your unit tests you assert that the view/layer state or rendered image matches a saved (by name) template. If the template doesn't exist in the test bundle or doesn't match the saved version, a new encoded state or rendered TIFF is produced for review. GTM provides categories for NSView and CALayer to do state encoding and rendering. Obviously you can override these categories on your own NSView or CALayer subclasses to encode relevant state (using the NSCoder protocol) or rendering.
It also allows you to (easily) programatically send key events and run the run loop from with unit tests and it supports unit testing on both OS X and iPhone.
I created an open source Python package that uses the Apple Accessibility API among others to create a classic GUI automation library, giving you visibility into and interaction with Cocoa GUIs. PyATOM home page
You might check out and consider Eggplant by TestPlant (formally Redstone Software) at http://www.testplant.com/.
Here is an article that Apple featured on them last year.
The latest CocoaCast podcast has an interview with Ian Dees the author of "Scripted GUI Testing with Ruby". You can find out more at CocoaCast

Resources