Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Setting the objectValue for the NSTextField by itself does not get down to the model.</p> <p>I'll try to explain what I'm doing. In my app I started with a simple textfield that has an NSDateFormatter attached to it. It was bound to an NSDate and all was well. Later I wanted to add a popup calendar next to the text field so a user could click their date.</p> <p><a href="http://media.clickablebliss.com/billable/interface_experiments/new_date_picker.png" rel="nofollow noreferrer">http://media.clickablebliss.com/billable/interface_experiments/new_date_picker.png</a></p> <p>Now rather than hard coding this behavior I tried to be generic with the solution. I ended up writing a custom helper object. I would connect the helper to the textfield and the button on screen and then set the action of the button to openPopup: in the helper. When the user popped up a calendar view my code would bind the calendar view to the same object that the textfield was bound to with the following code:</p> <pre><code>// Set the binding of the date picker in the panel to the same binding as the controlToBeHelped NSDictionary *controlToBeHelpedBindings = [controlToBeHelped infoForBinding:@"value"]; [popupPanelDatePicker bind:@"value" toObject:[controlToBeHelpedBindings valueForKey:NSObservedObjectKey] withKeyPath:[controlToBeHelpedBindings valueForKey:NSObservedKeyPathKey] options:nil]; </code></pre> <p>This works great in my one project. In my new project I'd like to reuse this code with a twist. This time the NSDate can be nil. I'd like to agument my code so that if the user clicks on the button to pick a date when the date is currently nil I first set it to now and then show the popup.</p> <p>Thus, I need to edit the NSDate this control is bound to via an IBOutlet. Thanks.</p> <p>EDIT: Thanks to Peter I think I got this working:</p> <pre><code>if ([[controlToBeHelpedBindings valueForKey:NSObservedObjectKey] valueForKeyPath:[controlToBeHelpedBindings valueForKey:NSObservedKeyPathKey]] == nil) { [[controlToBeHelpedBindings valueForKey:NSObservedObjectKey] setValue:[NSDate date] forKeyPath:[controlToBeHelpedBindings valueForKey:NSObservedKeyPathKey]]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload