문제

FirstController.m

- (IBAction)done:(id)sender {

    NSNotification *msg = [NSNotification notificationWithName:@"addNevItem" object:[NSString stringWithFormat:@"%i",1]];
[[NSNotificationCenter defaultCenter] postNotification:msg];

}

TwoController.m

- (void)viewDidLoad
{
    [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(addNevItem:)
                                             name:@"addNevItem"
                                           object:nil];
}

-(void)addNevItem:(NSNotification *)notification {

    NSLog(@"dd");

}

If the action is performed once, in the console I see one message. If the action is performed two times, in the console I see two more. If the action is performed three times, in the console I see three more. Why is this happening? I use the same code in other parts of the program and there is always only one message.

도움이 되었습니까?

해결책

you post a notification every time the action is executed so naturally you get just as much notifications

BUT

You have forgotten (or not shown ;)) to call removeObserver so notifications might 'pile up' (every living VC gets the notification)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top