我正在尝试创建自己的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
任何帮助将不胜感激,。
干杯。
答案 0 :(得分:2)
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:observer, @"o",selector, "s", nil];
看起来你错过了对我的“s”。
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:observer, @"o",selector, @"s", nil];
为了您的方便。