NSNotification
来源:互联网 发布:js onclick没反应 编辑:程序博客网 时间:2024/05/21 21:48
NSNotification
解释:消息
一个类执行另一个类的方法时使用
注册消息
[[NSNotificationCenter defaultCenter] //默认通知对象
addObserver:self /观察者,即在什么地方接收通知
selector:@selector(realizeNotificationButton) //收到通知后调用何种方法
name:@“mytest” //通知的唯一标示,编译器通过这个找到通知
object:nil
];
在另一个类里调用消息
[[NSNotificationCenter defaultCenter]
postNotificationName:@”mytest” object:nil];
相应消息
-(void)realizeNotificationButton
{
NSLog(@”消息”);
}
备注:
若在第二步调用消息时传递了参数(object)
注册消息,有冒号
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleFirstNotification:) name:@”first” object:nil];
在另一个类里调用时object候跟参数
[[NSNotificationCenter defaultCenter] postNotificationName:@”mytest” object:self.TextFile.text];
相应消息时
- (void)handleFirstNotification:(NSNotification *)notification
{
NSString str = (NSString )notification.object;接收参数
}
- NSNotification
- NSNotification
- NSNotification
- NSNotification
- NSNotification
- NSNotification
- NSNotification
- NSNotification
- NSNotification
- NSNotification
- NSNotification
- NSNotification
- NSNotification
- NSNotification
- NSNotification example
- NSNotification详解
- 通知 NSNotification
- NSNotification 译注
- jmeter&vmstat
- UITableView
- Centos下Yum安装PHP5.5,5.6
- linux安装svn
- 撤销修改
- NSNotification
- 传智播客西安中心之Android课程大纲
- 9Path图
- 【bbed】11g环境下编译安装bbed工具
- 千里之行,始于足下(一)-------配置AndroidManifest.xml
- iOS开发网络篇—监测网络状态
- 螺旋天线(又叫弹簧天线)
- Swift中的构造方法
- Sqlite的基本用法