NSDatePicker - getting the value when it is changed - objective-c

How would I get notified of a value of a NSDatePicker, when it's changed?

I've only done it on the iPhone with UIDatePicker but it is similar on the Mac, you register as a delegate and receive messages. See Apple's Docs here.
I should clarify, this tells you when it changed, you still need to call -dateValue to get the date.

The same you would any other control. Options are:
Target/Action
Binding
Observe notification
Delegate

You can bind the picker's value binding to a property of your controller, or a property of a model object (through a controller).

Related

Best way to bind custom NSView with custom NSObject

I'm trying to bind a property from a custom NSView to another on a custom NSObject. Both properties are simple bool value.
As a newbie with custom binding i've read Apple Documentation and searched on stackoverflow.
So I created a custom NSView and a custom NSObject, added a bool property called 'enabled' to both and bind them with [myCustomView bind:#"enabled" toObject:myObject withKeyPath:#"enabled" options:nil];
My customView use the approach explained in this article http://www.tomdalling.com/blog/cocoa/implementing-your-own-cocoa-bindings/ to notify value's changes and prevent memory retain issues.
I started my app, it works ! Wonderful ... but it's only one way binding ! When I click my customView, the custom object's property is updated (right) but if the custom object's property value change, my custom view's property isn't updated (Grrrr)
I'm a bit confused because as far as i understood custom bindings, Apple recommendation is to manually implement bind:toObject:withKeyPath:options and register an observer to track property's value changes and Tom Dalling's approach says the opposite.
So what is the best way to bind my properties in a bi-directional way ?
This SO answer here indicates that you just setup a symmetric binding going the other way. I haven't tried this, but it sounds like the following will work.
[myObject bind:#"enabled" toObject:myCustomView withKeyPath:#"enabled" options:nil];
I'm a bit confused because as far as i understood custom bindings, Apple recommendation is to manually implement bind:toObject:withKeyPath:options and register an observer to track property's value changes and Tom Dalling's approach says the opposite.
You have to implement both. You have to observe myObject with keypath #"enabled" so when myObject.enabled changes you can change myCustomView.enabled. You have to set myObject.enabled when myCustomView.enabled changes.
See Responding to Changes

Edit titles of `NSOutlineView` inline

I have an NSOutlineView and want to be able to edit the title of the entries in that list.
The list seems to support this by default but then the error is thrown as soon as I hit enter:
Exception detected while handling key input.
-[NSProxy doesNotRecognizeSelector:controlTextDidEndEditing:] called!
I tried to implement this method in my delegate but it did not get called.
I am having this problem with a PXSourceList but I think it is a general NSOutlineView issue.
This was a bug in PXSourceList and is now fixed in version 2.0.3:
https://github.com/Perspx/PXSourceList/releases/tag/2.0.3
The fact that an NSProxy is responding to your delegate call tells you that your own delegate is not connected to the outline view's delegate.
Check your delegate is connected to the outline view and look at the following documentation regarding delegates.
https://developer.apple.com/library/mac/qa/qa1551/_index.html

Objective-C: Date picker and level indicator

I'm using an NSDatePicker and NSLevelIndicator to try and set/display certain values of an object. I don't want to use bindings. My first thought would be to try and set a delegate of the date picker/level indicator to be my controller class so that I can be notified when either of those is changed. However, NSDatePicker and NSLevelIndicator don't have a delegate (at least, none that I can see in interface builder). How then do I keep track of when these things are changed?
NSControl and its subclasses use the target / action mechanism to alert you when their value changes. Some delegate protocols work in a similar manner, but in general delegates are used to modify the behavior of an object, while target / action alerts your controller of a change in a UI control.

3 notifications instead of one

I'm developing simple MVC app in Cocoa/Objective-C. I have a strange issue (or misunderstanding) with notifications and KVO.
I have AppController object in MainMenu.xib, hence I implement awakeFromNib method where I register for NSImageView changing its image property. I add self as an observer in the following way:
// options:3 equals to new/old passed values in changeDictionary
[backgroundImageView addObserver:self
forKeyPath:#"image"
options:3
context:NULL];
The backgroundImageView is an IBOutlet in AppController connected to NSImageView.
In standard observeValueForKeyPath:ofObject:change:context method I just log the received notification.
Problem is - when i change the image value of NSImageView I get 3 notifications instead of one. Can you help me with this? Maybe I'm overlooking something in options or in generally registering observer?
UPDATE: backgroundImageView is the instance of BackgroundImageView class which is sublcass of NSImageView. I subclassed the latter one for handling drag and drop operations as drag destination. When performDragOperation: is called (the last 'state' of the dragging) it changes the value for image property with setImage between willChangeValueForKey and didChangeValueForKey.
… it changes the value for image property with setImage between willChangeValueForKey and didChangeValueForKey.
When you send an accessor message, you get KVO notifications for free with it. You should remove the {will,did}ChangeValueForKey: messages, because they're the cause of at least one of the extraneous change notifications.
Is your AppController the File's Owner of two other nibs? If so, it'll receive an awakeFromNib message for each of those, too. MainMenu plus two makes three awakeFromNib messages, which means you'll add yourself as an observer three times.
There does not seem to be any obvious problem with setting of the observer.
Have a look at how you update the image that you observe, maybe it's being modified 3 times?

Observing a UISlider's value - iPhone KVO

By default, when I observe the value of a UISlider, it only updates once, when the slider is clicked, not continuously, even thought that is the slider's setting.
Is there a way to get the continuous value change of the slider?
UIKit doesn't actively support KVO. You may be getting lucky in that some notifications may make it through the usual mechanisms, but for the most part you shouldn't assume you can use KVO with any UIKit class.
You should instead get your continuous events through the UISlider's associated target's action method.
the continuous updating applies to the calling of the target method of the "value changed" event on the slider. I don't know how to do this with KVO