基础用法和通知的使用不多说,只将自己如何发送通知,同时观察自己的通知,并执行方法。
1.设置通知名,并发送通知。
#define SYAuthorizeResponseCompleted @"authorizeResponseComplete"
NSNotification *notification = [NSNotification notificationWithName:SYAuthorizeResponseCompleted object:self];
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
[defaultCenter postNotification:notification];
2.设置监听和移除监听
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
[defaultCenter addObserver:self selector:@selector(authorizeCompletle) name:SYAuthorizeResponseCompleted object:nil];
}
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:YES];
[[NSNotificationCenter defaultCenter] removeObserver:self name:SYAuthorizeResponseCompleted object:nil];
}
PS:设置监听和移除监听一定要成对存在。