创建我自己的NSNotificationCenter,存储对象?

时间:2012-08-08 22:04:40

标签: ios nsnotificationcenter nsnotifications

我正在尝试创建自己的NSNotificationCenter,以便更好地进行编程。我遇到了一个我无法解决的EXC_BAD_ACCESS。

我的方法:

- (void)addObserver:(id)observer forKey:(NSString *)theKey withSelector:(SEL)block {
    NSString *selector = NSStringFromSelector(block);
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:observer, @"o",selector, "s", nil];
    [[observers objectForKey:theKey] addObject:dict];
}

我在NSDictionary *dict的初始化中收到错误,我不明白为什么。正在添加的观察者是UIViewController,如果重要的话,它会在viewDidLoad applicationDidFinishLaunching中调用此方法。

我收到错误EXC_BAD_ACCESS code = 1

任何帮助将不胜感激,。

干杯。

1 个答案:

答案 0 :(得分:2)

NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:observer, @"o",selector, "s", nil];

看起来你错过了对我的“s”。

NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:observer, @"o",selector, @"s", nil];

为了您的方便。