How to set the action of a NSButton in a binding scenario? - cocoa

I have a button that is inside a view repeated inside a NSCollectionView. I can bind the title of the button to one of the properties in my model class but I want to wire the selector of the button to one of the selectors in my model class. Obviously, the button must send the message to the model object associated with the corresponding collection view item.
I managed to bind the target for the button but how to set the selector? I want to do that in Interface Builder if possible...

I figured it out. In the Ib there is a selector textbox bellow the path textbox where I bind the target. I don't know why I didn't see it. I spent nearly one hour trying to solve this issue.

How to add those blindings? I still can't find it.
I find it . It's Here.

Related

Monotouch dialog- Multiple textfield in single element?

I am using Monotouch dialog with Mvvmcross. My requirement is to have multiple textfield in single element/cell. But in Entryelement we have only one value property which has by default two way binding. Rest of the property are with only one way binding.
I have also tried with UIViewElement but same thing I can bind only one way. UI will update based on changes of ViewModel. But if something user will enter into textfield then how to fire ValueChange for it is challenge for me.
It would be good if somebody can point out rough steps to achieve it.

Can I set a property when created with bindings?

I'm trying to build a To-do list application. I have 2 tablesviews and one textfield. In the first tableview are the different projects, and when you click on one of them the associated todos appear in the second tableview. It's a pretty basic Master-detail I guess.
I set it all up with bindings.
Right now the way you add a task, is you click on an add button and it adds a row with a placeholder text that's editable.
But what I want, is the user to enter the task in the textfield, press add, and then it adds the todo with the name already set.
So basically I have TodoItem Class with a name property, and my question would be, how do I get the content of the nstextfield and assign it to the name property ?
I tried creating an outlet from the Todoitem class to the textfield, but xcode won't let me connect it....
Tell me if you need to see any code, but since I used bindings, there's almost nothing to show. Thanks!
… how do I get the content of the nstextfield and assign it to the name property ?
Translate that directly into Objective-C:
NSString *contentOfTheNSTextField = [myTextField stringValue];
myNewTask.name = contentOfTheNSTextField;
You'd do that in the action method that you've set both the button and the field to call.
I tried creating an outlet from the Todoitem class to the textfield, but xcode won't let me connect it....
To do this, the Todoitem would need to reside in the nib.
But, even if you could do that, why should the model object know about the text field? Carrying values between model and view is a controller's job.

WP7 Listbox Binding: Changing image uri in does not reflect in listbox

I have a view with a list box, bound to am obvervable collection of DisplayItems, which has 'Label', 'DisplayValue' and 'IconUri' properties.
I have a View Model which exposes this observable collection. The List Box is correctly populated first time around.
I then have a button which takes action on the selected item. I need to indicate that action has been taken by changing the image.
I am changing the IconUri of the selected item, and can see the new value present when debugging, but the image doesn't change. I can also change the 'Label' and 'DisplayValue' properties and see the new values correctly there when debugging, but the list doesn't change.
My ViewModel implements INotifyPropertyChanged. My DisplayItem class implements INotifyPropertyChanged. I'm calling RaisePropertyChanged I'm sure in too many places rather than too few.
None of the changes are ever reflected on screen.
I'm using a DataItemTemplate for the generated rows. If I could access the image of the selected row I could change it manually, but I can't even do that.
Any help greatly appreciated. I could actually do with a example of a list box displaying items from a bound observable collection, where one property of the selected item is changed and that change is reflected in the list box.
Thanks in advance
A
You didn't implement INotifyPropertyChanged correctly, or you're using it wrong.

Giving a Boolean property to a controller object in Interface Builder

After I drag a controller object to the document window, how do I give it a Boolean property?
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.
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.

Basic Cocoa Bindings: Toggle a boolean from menu in IB

I'm just getting started with Cocoa Bindings and while I've read through much of the documentation, I'm still struggling to implement a basic feature, making me question wether I'm doing it wrong or perhaps it's just not possible via IB.
Goal: Have a menu item called "Toggle visibility" toggle the state of a Boolean property in my application controller (AppController) called "visibility." I think this should be possible completely through IB.
(Note: CoreData is not in use here)
What I think needs to happen is I need to have an NSObjectController who's content outlet is set to my AppController class. Then I think I need to use an Action Innvocation binding. But here's where I run into trouble.
Should the Controller Key be selection? Should the Model Key Path be the name of my Boolean Property? What should Selector Name be?
Or do I need to setup a separate action method called "toggleVisibility" that I can bind to? If I did, why wouldn't I just use standard target/action associations, rather than bindings?
Any input / direction appreciated.
Goal: Have a menu item called "Toggle visibility" toggle the state of a Boolean property in my application controller (AppController) called "visibility."
Your goal tells you why you are failing.
In your description of your goal, you say that you want to set this menu item up as a command, a verb, an imperative sentence—“toggle the visibility”. But that's not the right title for the menu item.
Moreover, implementing a verb menu item with Bindings is inherently difficult because Bindings is the wrong tool for the job. Bindings is for exposing properties in your UI. It isn't for performing commands.
The correct title is supported by the correct Bindings-based solution.
The correct title of the menu item is, simply, “Visible”.
This alone should give you a hint as to how to proceed. Here's another: When the selection is visible, the menu item should have a check mark; when it is not visible, the menu item should have no mark.
You want to bind a property of the menu item to, ultimately, a Boolean property of your controller. Normally, this property of the menu item would be state, but for whatever reason, the binding for it is named value.
So, bind the value binding of the menu item to the Boolean property of your controller.

Resources