key-value-observing

How to add an object to a programatically bound NSMutableArray?

ⅰ亾dé卋堺 提交于 2019-12-08 04:15:54
问题 I have an NSDocument which has the following structure: @interface MyDocument : NSDocument { NSMutableArray *myArray; IBOutlet NSArrayController *myArrayController; IBOutlet MyView *myView; } @end I instantiate the NSArrayController and the MyView in MyDocument.xib, and have made the connections to the File's Owner (MyDocument), so I am pretty sure that from the point of view of Interface Builder, I have done everything correctly. The interface for MyView is simple: @interface MyView : NSView

How to observe torchLevel in swift?

本秂侑毒 提交于 2019-12-08 03:23:53
问题 How do I observe torchLevel? I have done the following from objective c solutions, no success: private var torchLevel = 0 let device = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo) device.addObserver(self, forKeyPath: "torchLevel", options: .New, context: &torchLevel) override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) { if context == &torchLevel { let device = object as!

How to create a binding for NSApp.dockTile's

社会主义新天地 提交于 2019-12-08 01:35:55
问题 In IB it is easy to bind a label or text field to some controller's keyPath. The NSDockTile (available via [[NSApp dockTile] setBadgeLabel:@"123"]) doesn't appear in IB, and I cannot figure out how to programmatically bind its "badgeLabel" property like you might bind a label/textfield/table column. Any ideas? 回答1: NSDockTile doesn't have any bindings, so your controller will have to update the dock tile manually. You could do this using KVO which would have the same effect as binding it.

Cocoa: Avoiding 'Updates Continuously' in control binds

江枫思渺然 提交于 2019-12-08 01:34:18
问题 I have several panels that contain NSTextField controls bound to properties within the File's Owner object. If the user edits a field and then presses Tab , to move to the next field, it works as expected. However if the user doesn't press Tab and just presses the OK button, the new value is not set in the File's Owner object. In order to workaround this I have set Updates Continuously in the binding, but this must be expensive (EDIT: or at least it's inelegant). Is there a way to force the

AVPlayer removing observer crash in Swift 2.2

[亡魂溺海] 提交于 2019-12-07 17:31:22
问题 I have a video app that I built a while back in Swift 1 and I've been trying to migrate to Swift 2.2. It all (finally) works apart from a weird crash to do with observers. func removeObservers() { print("REMOVING OBSERVERS") if ( !self.is_image && self.player != nil ) { if (self.player?.observationInfo != nil) { self.player?.removeObserver(self, forKeyPath: "currentItem.status") self.player?.removeObserver(self, forKeyPath: "readyForDisplay") } } NSNotificationCenter.defaultCenter()

KVO for one-to-many but NSNull object passed into observeValueForKeyPath

ε祈祈猫儿з 提交于 2019-12-07 15:29:21
问题 I have one managed object with a one-to-many relationship to member class. When I add the observers for members, it worked. When one new member is added to the relationship, the observeValueForKeyPath will be invoked with the new object and change dictionary contains the new member object. However, observeValueForKeyPath will be triggered second time with all values nil and change dictionary new="NULL". What is the second trigger? I set a breakpoint, but not sure who made the trigger.

How handle streaming error with AVPlayer

亡梦爱人 提交于 2019-12-07 10:45:17
问题 I use AVPlayer to stream tracks.I'm trying to handle all errors like network unavailable or stream unaivalable But I find any handler for this kind of error. I've already added a KVO for on the avplayer's status. [self.player addObserver:self forKeyPath:@"status" options:0 context:nil]; But even the stream doesn't exist (example: wrong url), the status switch to AVPlayerStatusReadyToPlay. EDIT Solution was to work with AVPLayerItems and use AVQueuPlayer. The other problem was I reallocated

Why is my NSOperation subclass never finishing?

瘦欲@ 提交于 2019-12-07 10:31:09
问题 I have an NSOperation subclass that I want to run concurrently. My understanding is that for concurrent operations to work: I need to define isConcurrent to return YES . I need to define the start method I need to send KVOs notification for isExecuting and isFinished when it's done. Using @synthesize will automatically send the appropriate KVO notifications when the values for isExecuting and isFinished are changed. Despite this, I have verified that my queue never moves on to the next item.

KVO object properties within to-many relationship

一个人想着一个人 提交于 2019-12-07 10:10:29
问题 I have a Core Data to-many relationship consisting of Parent <--->> Child. I would like to setup a key-value observing mechanism such that when a property (e.g. firstName, lastName) on any of the Child objects changes it triggers a notification. When using the standard KVO syntax: [self.parentObject addObserver:self forKeyPath:@"children" options:NSKeyValueObservingOptionNew context:NULL] this only notifies when the relationship itself is modified (i.e. a Child object is added or removed from

Observing a UISlider's value - iPhone KVO

你说的曾经没有我的故事 提交于 2019-12-07 05:35:47
问题 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? 回答1: 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