views:

34

answers:

2

After I drag a controller object to the document window, how do I give it a Boolean property?

A: 

Assuming you want the ability to expose and edit the property values of your custom controller as attributes showing up in IB's inspector, you'll need to write your own plugin which tells IB what the inspector should look like. This really can't be answered briefly.

Here's Apple's reference on IB Plugins: http://developer.apple.com/mac/library/documentation/DeveloperTools/Conceptual/IBPlugInGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40004323-CH1-SW1

And here's the inspector portion: http://developer.apple.com/mac/library/documentation/DeveloperTools/Conceptual/IBPlugInGuide/CreatingInspectors/CreatingInspectors.html#//apple_ref/doc/uid/TP40004323-CH6-SW1

If you truly just want to add a property to the controller's interface, you do this in Xcode (modifying the interface and implementation accordingly) and IB will pick up the changes automagically.

Darryl H. Thomas
I just want to give it a Boolean property because I heard that's what needs to be done if I want to have a textbox write something in response to the user checking a checkbox using bindings. What needs to be done?
Phenom
A: 

In the case of a checkbox, the checkbox itself is either checked or not. That state stores the boolean value instead of the controller (unless you wish it.)

To have the app undertake an action upon clicking it, think of it as a button instead of a data display and link it to an action method in the view controller. That's the simplest and old school way of doing it.

To use binding, you need to bind the checkbox's value attribute to a controller. Usually for binary values its an object controller. So, in IB, drag an Object controller to your nib window and bind it to your data source. Then, drag a checkmark button to the interface. In the checkmarks binding inspector. Set "value" binding to the name of the object controller, controller key to selection, keypath to the name of the data source attribute and provide a value transformer if needed.

TechZen
Everything seems to make sense except the part about the data source. What data source? Do I have to type something in XCode to create it?
Phenom
The datasource is whatever object you're using to manage your data model. It varies form app to app. If the app is simple it might just be a property in the view controller or a setting in user defaults. If the app is complex, then it could be Core Data, a SQL interface, download from a URL etc. That's only if you want to use binding. It sounds like you probably just want to treat the checkmark as a button and take an action when the user changes it.
TechZen
I'm just trying to understand how to do binding by making a simple example. I want to make it as simple as possible.
Phenom
Actually, a boolean value is slightly more complicated because its not an object. Use a NSString. instead. Just remember that you bind to a keypath that describe the path to a value inside an object or series of objects.
TechZen