代码改变世界

通知中心

2015-10-09 15:13  Y了个J  阅读(206)  评论(0编辑  收藏  举报

// 发出通知

    [[NSNotificationCenter defaultCenter] postNotificationName:HMTabBarDidSelectNotification object:nil userInfo:@{HMTabBarSelectIndex : @(button.tag)}];

postNotificationName : 通知名称

object:设法通知的,可以不写,不告诉别人是谁发出的

userInfo:将要传出去的参数

 

//接受通知

//监听键盘的通知(只要键盘改变frame的时候就会通知)

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];

//Observer:self 自身

//selector:监听后调用的方法

//name:监听通知的名称,

//object:监听的对象,nil 可以是任何对象

 

//移除通知

-(void)dealloc

{

    //移除观察者

    [[NSNotificationCenter defaultCenter] removeObserver:self];

}