KVO的使用(1)

1、在某个类中添加下面方法:

 

-(void)viewWillAppear:(BOOL)animated{

 

  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(oneObjHandleInfo:) name:@"NotificationViewController" object:nil];

}

-(void)viewWillDisappear:(BOOL)animated{

 

[[NSNotificationCenter defaultCenter] removeObserver:self];

 

}

//

-(void) oneObjHandleInfo:(NSNotification*) notification{

    //取得接受数据并打印

   NSString *getsendValue = [[notification userInfo] valueForKey:@"Key-name"];

    NSLog(@"=====%@========",getsendValue);

}

 

2、实现通知:可以直接放在不同的类文件中,也可以在本文件中调用

  [[NSNotificationCenter defaultCenter] postNotificationName:@"NotificationViewController" object:self userInfo:@{@"Key-name":@"Value-name"}];

 

posted @ 2015-04-28 11:46  穿山甲随笔-iOS开发  阅读(157)  评论(0编辑  收藏  举报