で通知名のために観察すると、私はそうのように、特定の通知名を見て切り替えるためのメソッドを持つオブジェクトを持っています。しかし、同じ通知に応答する必要がある別の方法handleB:
があります。NSNotificationCenterだから、複数の方法
- (void)startWatchingForB
{
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(handleB:)
name: SomeNotificationName
object: nil];
}
- (void)stopWatchingForB
{
[[NSNotificationCenter defaultCenter] removeObserver: self
name: SomeNotificationName
object: nil];
}
問題は、stopWatchingA
またはstopWatchingB
が呼び出されるべきであるということである、オブジェクトは両方のために見て停止します。 1つの観測インスタンスを削除する方法はありますか?
stopWatchingForA
を呼び出すと、handleA:
が呼び出されないようにするのが理想的です。B
から完全に独立しています。
はい、[@ implementation'のivarsの宣言は正当です](https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocDefiningClasses.html#//apple_ref/doc/uid/TP30001163-CH12-TPXREF126)をコンパイルしてください。 –
さらに便利な機能の1つ! @private実装変数は多くの点で有用です。 –
+1はよく考えられた答えです!私は受け入れますが、私が行った方法ではありません。私は私の答えで説明します。 –