通知的一个注意事项

2016-04-12  本文已影响40人  飞雨2013

关于通知的知识网上已有不少介绍,这里就不不做多余的说明了,想提醒的就是

在你发送通知的时候,一定要先有监听者监听才可以,否则将会导致第一次发出的通知无法监听的问题

#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

上一篇 下一篇

猜你喜欢

热点阅读