0

将对象添加到 NSMutableDictionary 时,如何使用 NSNotificationCenter 获取通知?

还有关于不可变 NSDictionary 的通知吗?

4

1 回答 1

1

继承之美:)

#define kSomeDictionarySetAValue @"SomeDictionarySetAValue"

@interface SomeDictionary : NSMutableDictionary

@end

@implementation SomeDictionary

- (void) setValue:(id)value forKey:(NSString *)key
{
    [super setValue:value forKey:key];

    [[NSNotificationCenter defaultCenter] postNotificationName:kSomeDictionarySetAValue
                                                        object:self];
}

@end
于 2012-08-03T13:36:42.143 回答