Anthony Shintoluggenprog Anthony Shintoluggenprog - 17 days ago 8
Objective-C Question

Can I use NSNotificationCenter selector method in multiple view controllers?

I have this

ViewControllerA
that pushes
ViewControllerB
onto the navigation stack, which pushes
ViewControllerC
onto the stack.

From
ViewControllerB
, I can pop to
ViewControllerA
.
And from
ViewControllerC
, I can pop to
ViewControllerA
.

I need to pass an
NSNumber
to
ViewControllerA
from either
B
and
C
(depending on which controller I'm using to pop to
A
).

I am going to incorporate the following:

- (void)viewDidLoad
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(getUpdate:)
name:@"getUpdateForCell"
object:nil];
}


and implement:

- (void)getUpdate:(NSNotification *)notification {
NSDictionary *data = [notification userInfo];
// pop
}


Can I use/implement
getUpdate:
in both
ViewControllerB
and
ViewControllerC
?

Answer

For one connections like from ViewControllerC to ViewControllerB you can use @protocol (delegation design pattern). But for tasks where you need to update something not from one place, you need to use NSNotificationCenter

So your implementation for current task is right.