2012-08-08 67 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]; 

爲了您的方便。