码迷,mamicode.com
首页 > 其他好文 > 详细

KVO的使用(1)

时间:2015-04-28 13:22:35      阅读:107      评论:0      收藏:0      [点我收藏+]

标签:

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"}];

 

KVO的使用(1)

标签:

原文地址:http://www.cnblogs.com/niexiaobo/p/4462587.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!