通知中心

// 发出通知

    [[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];

}

原文地址:https://www.cnblogs.com/yyj900165/p/4864031.html