Objective C 监听 通知
2013-09-22 14:23
169 查看
//添加监听
写在那里都行 要调用才行
[self addObserver:self forKeyPath:@"name" options:NSKeyValueObservingOptionNew context:nil];
2//实现监听器
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary
*)change context:(void *)context
{
NSLog(@"1.==========%@",keyPath);
//
NSLog(@"%@",__FUNCTION__);
}
3//只要有retain修饰的时候用
- (void)dealloc {
[_name release];
//移出监听
[self
removeObserver:self
forKeyPath:@"name"];
[super dealloc];
}
===========================================
4. 3/8 MVC
m :modal==数据
c:control===控制
v:view===展示
//创建通知
NSNotification *notifcation=[NSNotification notificationWithName:@"村委会"
object:nil];
//得到通知中心
发送通知
[[NSNotificationCenter defaultCenter]postNotification:notifcation];
//接受通知
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(print)
name:@"村委会" object:nil];
//移出通知
[[NSNotificationCenter defaultCenter]removeObserver:self name:@"村委会"
object:nil];
写在那里都行 要调用才行
[self addObserver:self forKeyPath:@"name" options:NSKeyValueObservingOptionNew context:nil];
2//实现监听器
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary
*)change context:(void *)context
{
NSLog(@"1.==========%@",keyPath);
//
NSLog(@"%@",__FUNCTION__);
}
3//只要有retain修饰的时候用
- (void)dealloc {
[_name release];
//移出监听
[self
removeObserver:self
forKeyPath:@"name"];
[super dealloc];
}
===========================================
4. 3/8 MVC
m :modal==数据
c:control===控制
v:view===展示
//创建通知
NSNotification *notifcation=[NSNotification notificationWithName:@"村委会"
object:nil];
//得到通知中心
发送通知
[[NSNotificationCenter defaultCenter]postNotification:notifcation];
//接受通知
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(print)
name:@"村委会" object:nil];
//移出通知
[[NSNotificationCenter defaultCenter]removeObserver:self name:@"村委会"
object:nil];
相关文章推荐
- 【Objective-C 语言】5 …
- objective-c 文件
- objective-c 中随机数的用法&…
- 转:objective-C 的OOP(下)-类(st…
- 【Objective-C 语言】7 …
- Linux netstat -tl 显示当前监听的…
- IOS Objective c 同步 异步链接 …
- iOS 分享新浪微博开发通知
- Notification---Notification使用详解之三:通过服务更新进度通知&在Activity中监听服务进度
- Android Notification 使用详解之三:通过服务更新进度通知&在Activity中监听服务进度
- 通过服务更新进度通知&在Activity中监听服务进度
- 【Objective-C 语言】8 …
- JDK7新特性 监听文件系统的更改
- objective-c 截取字符串 数组 字典…
- objective-c Objective-C语法之动…
- ORACLE 快速启动监听及相关服务程序
- Notification使用详解之三:通过服务更新进度通知&在Activity中监听服务进度
- kali linux:代理监听以及拦截
- 【Objective-C 语言】9 …
- Notification使用详解之三:通过服务更新进度通知&在Activity中监听服务进度