//添加监听 写在那里都行 要调用才行
[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];