2012-08-08 64 views
0

我想创建我自己的NSNotificationCenter只是为了更好地编程。我遇到了一个EXC_BAD_ACCESS,我无法完成。创建我自己的NSNotificationCenter,存储对象?

我的方法:

- (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错误代码= 1

任何帮助,将不胜感激,。

干杯。

+1

它不可能像在''s“之前缺少'@'一样简单吗? – 2012-08-08 22:11:06

回答

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

看起来你错过了@上“s”给我。

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

为了您的方便。