2017-01-15 17 views
0

ViewController.mは、[NSNotificationCenter defaultCenter]にオブザーバとして登録されています。でも、ViewControllerviewDidLoadの方法でXをします。オブザーバーがNSNotificationCenterから通知を受けたかどうかを知る方法はありますか?

私は通知を取得できませんでしたのみViewController場合Xが起こるしたいと思います。

アーキテクチャは実際には壊れているかもしれませんが、私の質問は、内部にデータがある場合です。defaultCenterは、オブザーバーに通知があるかどうかを教えてくれますか?

+1

通知のブロードキャストではなく、直接委任を調べたいと思うようなデザインの音が聞こえてきます。私は通知を「火の玉」と思うでしょう。 – luk2302

+0

あなたは正しいです、質問を編集しました。 – wp42

答えて

0

私たちが送信したかどうかを知るためのコールバック方法は、オブザーバによって受信されたnotificationです。

我々はXcodeで取得することができますNotification Center方法によると:

/**************** Notification Center ****************/ 
open class NotificationCenter : NSObject { 


    open class var `default`: NotificationCenter { get } 


    open func addObserver(_ observer: Any, selector aSelector: Selector, name aName: NSNotification.Name?, object anObject: Any?) 


    open func post(_ notification: Notification) 

    open func post(name aName: NSNotification.Name, object anObject: Any?) 

    open func post(name aName: NSNotification.Name, object anObject: Any?, userInfo aUserInfo: [AnyHashable : Any]? = nil) 


    open func removeObserver(_ observer: Any) 

    open func removeObserver(_ observer: Any, name aName: NSNotification.Name?, object anObject: Any?) 


    @available(iOS 4.0, *) 
    open func addObserver(forName name: NSNotification.Name?, object obj: Any?, queue: OperationQueue?, using block: @escaping (Notification) -> Swift.Void) -> NSObjectProtocol 
} 

そして、我々はNotificationCenterapple docsを参照することができ、我々はその機能を学ぶべきである:

オブジェクトの通知に登録addObserver(_:selector:name:object :)メソッドまたはaddObserver(forName:object:queue:using :)メソッドを使用して通知(NSNotificationオブジェクト)を受信することができます。

そして、docsからあなたの要件に関する記載が見つかりません。

+0

正解、ありがとう – wp42

関連する問題