NSNotificationCenter 例子

.h
 [[NSNotificationCenter defaultCenter] postNotificationName:@"wantuNewMessage"                                                    object:@"10"];


.m
- (void)viewDidAppear:(BOOL)animated{
    [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(showNewMessage:)
     name:@"wantuNewMessage"
     object:nil];
}

- (void)viewDidDisappear:(BOOL)animated{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)showNewMessage:(NSNotification*) notification{
    NSLog(@"wantu.showNewMessage");
    [notification object];
}

猜你喜欢

转载自longquan.iteye.com/blog/1705928
今日推荐