key-value-observing

Do I have to removeObserver in KVO manually

我与影子孤独终老i 提交于 2019-12-09 13:37:04
问题 I have read the apple document about KVO, and it said: Note: The key-value observing addObserver:forKeyPath:options:context: method does not maintain strong references to the observing object , the observed objects, or the context. You should ensure that you maintain strong references to the observing, and observed, objects, and the context as necessary. The observer object not have a strong references to the observered object. Does this man I can not call removeObserver:forKeyPath: in the

KVO on Swift's computed properties

ⅰ亾dé卋堺 提交于 2019-12-09 13:09:22
问题 just wondering if this is possible in Swift 2.2, KVO on a computed property!? ie: var width = 0 var height = 0 private var area : Double { get { return with * height } } self.addOberser(self, forKeyPath: "area", ...... Would a client code modifying the with or height trigger observeValueForKeyPath? Just checking before engaging on a mayor class refactor. KVO's syntax being as annoying as it's is not worth even a playground if someone has an answer at hand (I am assuming answer is NO) regards!

How should I handle the NSIndexSet from kvo to update a table view?

徘徊边缘 提交于 2019-12-09 07:33:31
问题 I am starting out using key value observing, and the mutable array I'm observing gives me NSIndexSets (Ordered mutable to-many) in the change dictionary. The problem is the table view as far as I know wants me to give it NSArrays full of indexes. I thought about implementing a custom method to translate one to the other, but this seems slow and I get the impression there must be a better way to make this table view update when the array changes. This is the method from my

KVO and NSMutableArray

穿精又带淫゛_ 提交于 2019-12-09 02:50:58
问题 How can I set KVO (key-value-observing) with an NSMutableArray ? I want to be notified when a change appears in the array. I never used KVO before with a collection like an array. 回答1: I think you'll be interested in the answers to this question. The key is that you can't observe any properties on the array directly—the array is just storage—but you can observe the to-many relationship that's backed by that array (here I'm assuming your array is a property on an object somewhere). If you don

Is it possible to observe a readonly property of an object in Cocoa Touch?

天涯浪子 提交于 2019-12-09 02:13:00
问题 I've attempted to observe the (readonly) visibileViewController property of a UINavigationController with no success. I was able to successfully observe a readwrite property I defined myself for testing purposes on another class. Is it possible to observer readonly attributes? 回答1: Yes, it is possible to observe read-only properties. However, if the object that declares that property makes changes to the value of that property in a way that is not Key-Value Observing compliant (e.g. changes

NSKeyValueObservation: Cannot remove an observer for the key path from object because it is not registered as an observer

*爱你&永不变心* 提交于 2019-12-08 14:54:22
问题 I get random crashes (which I can't reproduce on devices I own) in my app with exception: Cannot remove an observer Foundation.NSKeyValueObservation 0xaddress for the key path "readyForDisplay" from AVPlayerLayer 0xaddress because it is not registered as an observer. This happens when I deallocate a UIView which contains AVPlayerLayer. My init: private var playerLayer : AVPlayerLayer { return self.layer as! AVPlayerLayer } init(withURL url : URL) { ... self.asset = AVURLAsset(url: url) self

Any way to see who is triggering changes re: key value observing?

筅森魡賤 提交于 2019-12-08 12:06:14
问题 I'm using key value observing to perform specific actions whenever certain properties are changed (e.g., relayout subviews of a custom UIView whenever its frame or bounds change). Is there any way to see who (i.e., what function) is triggering this change? Putting a breakpoint in my observeValueForKeyPath:ofObject:change:context: doesn't help because I don't think I can see who caused the change to frame or bounds that caused KVO to be triggered. In my specific example, I can't figure out who

I didn't get any notifications when I touched on tabbar items

Deadly 提交于 2019-12-08 11:18:31
I have UITabbarCoo=ntroller application. I added an observer and I'm waiting for any notifications. I didn't get any notifications when I touched on tabbar items. [self.tabBarController addObserver:self forKeyPath:@"selectedIndex" options:NSKeyValueObservingOptionNew context:@"changedTabbarIndex"]; - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { NSString *action = (NSString*)context; if([action isEqualToString:@"changedTabbarIndex"]) { } } I noticed the same thing. I assume that this is a bug in the

I didn't get any notifications when I touched on tabbar items

心不动则不痛 提交于 2019-12-08 09:56:30
问题 I have UITabbarCoo=ntroller application. I added an observer and I'm waiting for any notifications. I didn't get any notifications when I touched on tabbar items. [self.tabBarController addObserver:self forKeyPath:@"selectedIndex" options:NSKeyValueObservingOptionNew context:@"changedTabbarIndex"]; - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { NSString *action = (NSString*)context; if([action isEqualToString:@

Observe value changes of NSDictionary inside NSArray

别等时光非礼了梦想. 提交于 2019-12-08 07:22:40
问题 here's my NSArray carType ( { isSelected = 0; kFieldName = "All types"; kObjectValue = 0; kObjectValueText = All; }, { isSelected = 0; kFieldName = "4 seats"; kObjectValue = 4; kObjectValueText = "4 seats"; }, { isSelected = 1; kFieldName = "7 seats"; kObjectValue = 7; kObjectValueText = "7 seats"; } ) how can I observe the change of isSelected field ? I used KVO in my code but it doesn't work. carType is a NSArray property of context - (void)viewDidLoad { [super viewDidLoad]; [context