我想將字典傳遞給方法processit。但是一旦我訪問字典,就會得到EXC__BAD_INSTRUCTION。如何在NSNotificationCenter中使用參數化方法?
NSNotificationCenter *ncObserver = [NSNotificationCenter defaultCenter];
[ncObserver addObserver:self selector:@selector(processit:) name:@"atest"
object:nil];
NSDictionary *dict = [[NSDictionary alloc]
initWithObjectsAndKeys:@"testing", @"first", nil];
NSString *test = [dict valueForKey:@"first"];
NSNotificationCenter *ncSubject = [NSNotificationCenter defaultCenter];
[ncSubject postNotificationName:@"atest" object:self userInfo:dict];
在收件人方法:
- (void) processit: (NSDictionary *)name{
NSString *test = [name valueForKey:@"l"]; //EXC_BAD_INSTRUCTION occurs here
NSLog(@"output is %@", test);
}
什麼,我做錯了什麼建議?
謝謝阿德里安更新代碼。從下次開始,我會照顧格式化。 :) – 2011-06-10 10:45:26