NSNotificationCenter 如果name是空?是什么效果?
Posted hherima
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了NSNotificationCenter 如果name是空?是什么效果?相关的知识,希望对你有一定的参考价值。
典型的NSNotificationCenter使用方法:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reachabilityChanged)
name:kReachabilityChangedNotification
object:nil];
下面是官方的文档
SummaryAdds an entry to the notification center's dispatch table with an observer and a notification selector, and an optional notification name and sender. | ||||||||
Declaration- (void)addObserver:(id)observer selector:(SEL)aSelector name:(NSNotificationName)aName object:(id)anObject; | ||||||||
DiscussionIf your app targets ios 9.0 and later or macOS 10.11 and later, you don't need to unregister an observer in its dealloc method. Otherwise, you should call removeObserver:name:object: before | ||||||||
Parameters
|
意思是如果name,是nil那么,无论谁发送通知,都会调用这个selector。
参考文章:http://southpeak.github.io/2015/03/20/cocoa-foundation-nsnotificationcenter/
以上是关于NSNotificationCenter 如果name是空?是什么效果?的主要内容,如果未能解决你的问题,请参考以下文章
UIApplicationWillTerminate:NSNotificationCenter 与 Application Delegate