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