ITeye博客

NSNotificationCenter 例子

修博龙泉 · 2012-10-26 13:56 · ios开发学习相关 · 移动开发 · Markdown

.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];
}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。