したがって、私の目標は、を使用して別のクラスに通知を配信することです。また、通知を他のクラスNSNotificationCenter
に渡したいのですが、どうすればよいですか?object
class
3728 次
2 に答える
7
最初に通知名を登録する必要があります
[[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];
}
于 2011-07-24T22:18:40.620 に答える
0
ここで説明されているように、通知を投稿するための任意のメソッドを呼び出すだけです。たとえば、次のようになります。
通知を投稿するには:
-(void)postNotificationName:(NSString *)notificationName
object:(id)notificationSender
userInfo:(NSDictionary *)userInfo;
whereuserInfo
は便利なオブジェクトを含む辞書です。
反対側で通知を登録するには:
-(void)addObserver:(id)notificationObserver
selector:(SEL)notificationSelector
name:(NSString *)notificationName
object:(id)notificationSender;
于 2011-07-24T22:15:42.010 に答える