草庐IT

observeValueForKeyPath

全部标签

ios - observeValueForKeyPath 没有被调用

我正在开发一个测试应用程序,其中有一个NSOperationQueue。我正在创建一个NSInvocationOperation并观察该操作的“isFinished”属性。奇怪的是,observeValueForKeyPath仅有时被调用。我无法理解每次都调用它必须进行的更改。请帮忙。这是我写的代码:-(BOOL)application:(UIApplication*)applicationdidFinishLaunchingWithOptions:(NSDictionary*)launchOptions{........//initializationqueue=[NSOperati

ios - AVPlayer 不在后台加载媒体

在后台运行时,我的AVPlayer实现无法播放下载的音频(例如播客),但能够播放本地存储的歌曲。无法在后台播放只有当手机与我的电脑断开连接时。如果我的手机直接连接到我的计算机/调试器,则任何本地媒体或下载的媒体都可以毫无问题地播放。在前台,播放任何一种媒体类型也没有问题。这是我的实现:AVPlayer*moviePlayer;AVPlayerItem*playerItem;NSURL*address=/*theurlofeitheralocalsongorremotemedia*/if(moviePlayer!=nil){NSLog(@"removingrate,playbackBuf

objective-c - 在附加到 NSOperationQueue operationsCount 的 observeValueForKeyPath 中崩溃

我的UIView子类中有UITextViewlogView(尝试了atomic和nonatomic)和NSOperationQueueuploadQueue属性.我在我的NSOperationQueue属性的operationsCount上添加了KVO,如下所示:[[selfuploadQueue]addObserver:selfforKeyPath:@"operationCount"options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld)context:NULL];观察者函数如下所示:-(void)obse

ios - KVO 在 iOS 9.3 中损坏

这可能是iOS9.3(发行版)中的一个严重错误。将单个观察者添加到[NSUserDefaultsstandardUserDefaults]时,我注意到响应方法-observeValueForKeyPath:ofObject:change:context:被多次调用。在下面的简单示例中,每次按下一次UIButton时,observeValueForKeyPath都会触发两次。在更复杂的示例中,它会触发更多次。它仅出现在iOS9.3上(在SIM卡和设备上)。这显然会对应用程序造成严重破坏。还有其他人遇到同样的情况吗?//ViewController.m(barebones,singlevi

ios - KVO 在 iOS 9.3 中损坏

这可能是iOS9.3(发行版)中的一个严重错误。将单个观察者添加到[NSUserDefaultsstandardUserDefaults]时,我注意到响应方法-observeValueForKeyPath:ofObject:change:context:被多次调用。在下面的简单示例中,每次按下一次UIButton时,observeValueForKeyPath都会触发两次。在更复杂的示例中,它会触发更多次。它仅出现在iOS9.3上(在SIM卡和设备上)。这显然会对应用程序造成严重破坏。还有其他人遇到同样的情况吗?//ViewController.m(barebones,singlevi

ios - 使用 - observeValueForKeyPath :ofObject:change:context: in Swift 3

我正在尝试将Swift2.2项目转换为Swift3,但出现以下错误:Method'observeValue(forKeyPath:ofObject:change:context:)'withObjective-Cselector'observeValueForKeyPath:ofObject:change:context:'conflictswithmethod'observeValue(forKeyPath:of:change:context:)'fromsuperclass'NSObject'withthesameObjective-Cselector"forthefunction

ios - 使用 - observeValueForKeyPath :ofObject:change:context: in Swift 3

我正在尝试将Swift2.2项目转换为Swift3,但出现以下错误:Method'observeValue(forKeyPath:ofObject:change:context:)'withObjective-Cselector'observeValueForKeyPath:ofObject:change:context:'conflictswithmethod'observeValue(forKeyPath:of:change:context:)'fromsuperclass'NSObject'withthesameObjective-Cselector"forthefunction

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

我有一个与成员类具有一对多关系的托管对象。当我为成员添加观察员时,它起作用了。当一个新成员被添加到关系中时,将使用新对象调用observeValueForKeyPath并更改包含新成员对象的字典。但是,将第二次触发observeValueForKeyPath,所有值为nil并更改字典new="NULL"。第二个触发点是什么?我设置了一个断点,但不确定是谁触发的。@interfaceFooObject:NSManagedObject{}@property(nonatomic,strong)NSString*fooId;@property(nonatomic,strong)NSSet*me

ios - bool 属性上的 KVO,不调用 observeValueForKeyPath

我有一个appDelegate,它有一个属性myWindowofMyWindowClass。我需要从myWindow观察bool属性。比起我有一个CustomViewController,它需要观察bool值的变化。如果我想添加Observer,我会在ViewController中执行以下操作:LayerWindow*w=((AppDelegate*)[UIApplicationsharedApplication].delegate).window;[waddObserver:selfforKeyPath:@"touchInsideLayerWindow"options:(NSKeyV

iphone - iOS observeValueForKeyPath 没有被调用

我在调用observeValueForKeyPath时遇到问题,但使用以下方法解决了它:observeValueForKeyPathnotbeingcalled不过,我想知道一般如何处理这个问题以供将来引用。有效的代码如下所示:-(void)input:(NSString*)digit{NSLog(@"input()-Entering...digit=%@",digit);if([digitslength]在此之前,我使用的是NSMutableString而不是NSString,只是说使用了appendString。我没有进行赋值,也没有将“self”附加到digits变量。是否有任何