您的位置:首页 > 移动开发 > Objective-C

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];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: