Reputation: 1037
I have an tab bar app and the 2 tabs use the same class (different instances) to show a UITableView. Based on which tab is clicked a few minor changes are made to the appearance, functionality etc. The problem I have is that from the UITableView I show a modal view and when it is dismissed it posts an NSNotification to reload the UITableView (handled by the UITableView's view controller), but I get 2 NSNotifications posted as there are 2 instances of the same class in my app. How can I get the notification be be posted in just the instance it is called from?
Upvotes: 0
Views: 853
Reputation: 58448
When you set up a handler for an NSNotification
you can specify an object
for whose notifications you are interested in.
You should set your first table view controller to only be interested in notifications that are posted from the specific instance of the modal view controller, and your second table view controller to only be interested in notifications posted from its specific instance of the modal view controller:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handler:)
name:notificationName
object:instanceOfModalViewController];
This way when a notification is posted from your modal view controller, only the table view controller that has specified its interest will handle the notification.
Upvotes: 3