如何在ObjectiveC中检查键值观察数组的字典? [英] How to check Key Value Observing in ObjectiveC for dictionary of arrays?
本文介绍了如何在ObjectiveC中检查键值观察数组的字典?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码:
@property (strong, nonatomic) NSMutableDictionary *todoSessionDict;
@synthesize todoSessionDict;
[self addObserver:self forKeyPath:@"todoSessionDict" options:NSKeyValueObservingOptionNew context:NULL];
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
}
------------------------
NSMutableArray *unCompletedTodosArr = [NSMutableArray array];
NSMutableArray *completedTodosArr = [NSMutableArray array];
[self.todoSessionDict setObject:unCompletedTodosArr forKey:@"unCompletedTodosArr"];
[self.todoSessionDict setObject:completedTodosArr forKey:@"completedTodosArr"];
任何想法如何使用KVO
检查self.todoSessionDict
中的@"unCompletedTodosArr" and @"completedTodosArr"
值是否已更改?
Any idea how to check if the @"unCompletedTodosArr" and @"completedTodosArr"
values are changed in the self.todoSessionDict
using KVO
?
推荐答案
首先,它应该是:
[self addObserver:self forKeyPath:@"todoSessionDict.unCompletedTodosArr" options:0 context:nil];
[self addObserver:self forKeyPath:@"todoSessionDict.completedTodosArr" options:0 context:nil];
对于这两种方法,
#pragma mark - KVO
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
// Here your actions depends on the key path...
}
-(void)didChangeValueForKey:(NSString *)key
{
}
这篇关于如何在ObjectiveC中检查键值观察数组的字典?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文