swift编程 NSNotificationCenter
来源:互联网 发布:2016腾讯游戏数据分析 编辑:程序博客网 时间:2024/05/22 08:27
NSNotificationCenter消息通信机制介绍
作用:NSNotificationCenter是专门供程序中不同类间的消息通信而设置的.
注册通知:即要在什么地方接受消息
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mytest:) name:@" mytest" object:nil];
参数介绍:
addObserver: 观察者,即在什么地方接收通知;
selector: 收到通知后调用何种方法;
name: 通知的名字,也是通知的唯一标示,编译器就通过这个找到通知的。
发送通知:调用观察者处的方法。
[[NSNotificationCenter defaultCenter] postNotificationName:@"mytest" object:searchFriendArray];
参数:
postNotificationName:通知的名字,也是通知的唯一标示,编译器就通过这个找到通知的。
object:传递的参数
注册方法的写法:
- (void) mytest:(NSNotification*) notification
{
id obj = [notification object];//获取到传递的对象
}
附:注册键盘升启关闭消息
- //键盘升起
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
- //键盘降下
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
0 0
- swift编程 NSNotificationCenter
- swift 中使用 NSNotificationCenter
- Swift NSNotificationCenter的使用
- iOS Swift NSNotificationCenter 通知
- Swift开发:NSNotificationCenter 传值
- NSNotificationCenter 编程简介
- 深入浅出Swift(5)—— NSNotificationCenter
- Swift - 使用NSNotificationCenter发送通知,接收通知
- Swift里通知的使用NSNotificationCenter
- swift中通知NSNotificationCenter的使用
- NSNotificationCenter
- NSNotificationCenter
- NSNotificationCenter
- NSnotificationcenter
- NSNotificationCenter
- NSNotificationCenter
- NSNotificationCenter
- NSNotificationCenter
- 一个程序启动一个exe
- bootstrap-table后台分页时前台删除最后一页所有数据refresh刷新后无数据问题。
- OracleBulkCopy批量插入数据
- windows下安装Python的XlsxWriter模块
- redis—-sorted set 类型详解
- swift编程 NSNotificationCenter
- 由入栈123出栈顺序引发的思考
- 了不起的全能MAC系统监测工具iStat Menus 5下载
- 仿京东分类页面h5的页面布局及css样式设置
- mmap使用
- 使用root用户远程登录mysql没有trigger权限的问题
- 解决IIS管理器的网站可访问但ftp无法访问的问题
- hdu 胜利大逃亡(BFS)(三维)
- SQL优化:对报表生成工具的改进