NSNotificationCenter是程序不同类间的消息通信.
注册消息通知:
1 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(mthMsg:) name:@"mthMsg" object:nil];
addObserver: 注册通知
selector: 收到通知后调用何种方法;
name: 通知的名字(唯一标示)。
发送消息通知:
[[NSNotificationCenter defaultCenter] postNotificationName:@"mthMsg" object:obj];
postNotificationName:消息的名称
//键盘注册通知1 //键盘升起 2 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; 3 //键盘降下 4 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
来源:https://www.cnblogs.com/wangshengl9263/p/3472781.html