質問

したがって、私の目標は、使用して別のクラスに通知を提供することです NSNotificationCenter, 、私も合格したいです object 他の通知で class, 、これをどうすればいいですか?

役に立ちましたか?

解決

最初に通知名を登録する必要があります

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startLocating:) name:@"ForceUpdateLocation" object:nil]; // don't forget the ":"

そして、パラメーターの辞書で通知を投稿します

[[NSNotificationCenter defaultCenter] postNotificationName:@"ForceUpdateLocation" object:self userInfo:[NSDictionary dictionaryWithObject:@"1,2,3,4,5" forKey:@"categories_ids"]]; 

そして、この方法は次のとおりです

- (void)startLocating:(NSNotification *)notification {

    NSDictionary *dict = [notification userInfo];
}

他のヒント

説明されているように通知を投稿する方法を呼び出してください ここ, 、 例えば :

通知を投稿するには:

-(void)postNotificationName:(NSString *)notificationName
                     object:(id)notificationSender
                   userInfo:(NSDictionary *)userInfo;

どこ userInfo 有用なオブジェクトを含む辞書です。

反対側で通知に登録する:

-(void)addObserver:(id)notificationObserver
           selector:(SEL)notificationSelector
               name:(NSString *)notificationName
             object:(id)notificationSender;

Appleを確認することもできます 通知プログラミングトピック.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top