gran33
gran33

Reputation: 12991

IOS- NSNotificationCenter- notify specific instance

I'm using NSNotificationCenter, the listener subscribe with the following code:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(editRSSLAbel:)
                                             name:@"editLabel"
                                           object:nil];

And the sender sends the notification with this posting:

NSDictionary *dataDict = [NSDictionary dictionaryWithObject:@"http://www.nba.com" forKey:@"link"];                                               

[[NSNotificationCenter defaultCenter] postNotificationName:@"editLabel" object:self userInfo:dataDict];

But, i want to notify a specifit viewController instance, and with the above machinisem i don't have the ebility to do so.

Any idea will be great!

Thanks in advance!

Upvotes: 1

Views: 161

Answers (2)

Dima
Dima

Reputation: 8662

Apple doesnt support this directly, you can register to this notifications with your App, not with your view, the os not familiar with your internal implementation, so you can add a dictionary with a name of the controller and hold a dictionary of names-controllers to forward it to the right view

Upvotes: 1

sbarow
sbarow

Reputation: 2819

You could add a new key with a tag in that data dictionary you are posting. In all of the view controllers that receive the notification check that tag to see if matches "their" tag is so then they can process the data or they can simply return from the method.

Upvotes: 1

Related Questions