문제

my code is crashing at:

[[NSNotificationCenter defaultCenter] postNotificationName:kgotNotification object:dictionary];

my assumption is that I am posting a notification before the observer is added.

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getItems:) name:kgotNotification object:nil];

is there a way to check for the list of active observers before posting a notification?

도움이 되었습니까?

해결책

You should do it like this:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getItems:) name:kgotNotification object:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:kgotNotification object:self userInfo:dictionary];

Then your getItems Method:

-(void)getItems:(NSNotification* )note
{
    NSLog(@"UserInfo: %@", note.userInfo);
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top