通知的一個(gè)注意事項(xiàng)

關(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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容