1

I have implemented an navigation based view controller with several views and a model.

Now I add my navigation controller to the Tabbar via interface builder. (just dragged the whole bunch into it). It worked, I have got a new tab with all my views in it.

But now I want to add exactly the same navigation view controller again to another tab. I can also do this, the problem is, when I e.g. delete an entry in my table view, the entry is still visible in the other tab.

So what I need a way to update my model when I switch the tabs.

Update:

I added the addObserver in my RootViewController containing the table view. I placed it in "view did load", the postNotification in my delete method. No compile Errors, but also the tables do not update each other.

I uploaded my project, perhaps you could have a look?:

http://www.perry-paul.de/unternehmenf.zip

Kev
  • 118,037
  • 53
  • 300
  • 385
Subseven
  • 11
  • 1

1 Answers1

2

One way of doing this is by using NSNotifications.

When you load your view controller containing the tableView, sign up your tableView for notifications using

[[NSNotificationCenter defaultCenter] addObserver:self.tableView selector:@selector(reloadData) name:@"ModelUpdated" object:nil];

That way [self.tableView reloadData] will get called every time you post the "ModelUpdated" notification. So when you delete a entry, send out the notification using

[[NSNotificationCenter defaultCenter] postNotificationName:@"ModelUpdated" nil];

Finally, don't forget to remove the notification (usually in viewDidUnload):

[[NSNotificationCenter defaultCenter] removeObserver:self name:"ModelUpdated" object:nil];

More info on NSNotifications in this question: What is NSNotification?

Community
  • 1
  • 1
Domestic Cat
  • 1,434
  • 11
  • 18