3

オブジェクトと送信者で通知を投稿する方法がわからないようです。

名前、送信者、ユーザー情報を記載した通知を投稿できます。見る:

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

また、オブジェクトを使用してNSNotificationを投稿することはできますが、送信者をオブジェクトにリンクすることはできません。

NSNotification *notification = [NSNotification notificationWithName:name
                                                             object:someObject];
[[NSNotificationCenter defaultCenter] postNotification:notification];

(a)オブジェクトと(b)送信者参照を使用して通知を投稿する方法を教えてもらえますか?

4

1 に答える 1

16

提案する両方の方法で、object変数は通知の送信者を表します。これは、本当に必要なものであれば何でもかまいません。通知で追加のオブジェクトを提供するために、オブジェクトを含む辞書をに渡すことができますuserInfo

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                                      someObject, @"someObject",
                                      anotherObject, @"anotherObject", nil];
[[NSNotificationCenter defaultCenter] postNotificationName:name
                                                    object:sender
                                                  userInfo:options];
于 2011-05-08T21:27:30.650 に答える