關(guān)于通知的知識(shí)網(wǎng)上已有不少介紹秋茫,這里就不不做多余的說(shuō)明了携狭,想提醒的就是
在你發(fā)送通知的時(shí)候,一定要先有監(jiān)聽(tīng)者監(jiān)聽(tīng)才可以,否則將會(huì)導(dǎo)致第一次發(fā)出的通知無(wú)法監(jiān)聽(tīng)的問(wèn)題
#import#import "ViewController.h"
@interface Alvin : NSString
@end
@interface Alvin (one)
+ (void)PutOne;
@end
@interface Alvin (two)
+ (void)PutTwo;
@end
#import "Alvin.h"
@implementation Alvin
- (void)dealloc
{
[super dealloc];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end
#import "Alvin.h"
@implementation Alvin (one)
+ (void)PutOne
{
NSLog(@"one");
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(btnone) name:JUMPSUCCESS object:nil];
}
+ (void)btnone
{
NSLog(@"ALvin one");
}
@end
#import "Alvin.h"
@implementation Alvin (two)
+ (void)PutTwo
{
NSLog(@"two");
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(btntwo) name:JUMPSUCCESS object:nil];
}
+ (void)btntwo
{
NSLog(@"ALvin two");
}
@end