views:

38

answers:

2

I have a list of websites in a plist, when the app loads this populates a tableview (which is inside a navigation controller)

But I have added an add button to the navigation bar and then created another View Controller to deal with inputting of the new website (Like Title and URL). It is very similar to how the contacts app looks. There is a table view and when you tap add, the add UI slides up. I have got all this working great so far.

My Problem is what happens when the user taps Done. I can add the website to the plist (each website is a dictionary in the plist with 2 keys, atm) But then how do I tell the tableView to update? The table view has not been removed from the main window, just the add view has been added on top of the "screen".

Another way of asking is, when you tap Save on Add a Contact screen: (not my image) http://www.iphone-recovery.com/wp-content/uploads/2008/01/jcontact.jpg How does the new contact's data (Xyz's data) get shown on the tableview?

+1  A: 

You could use NSNotifiactionCentre to notify the other view. Just have the tableViewController listen for the correct NSNotification, and respond accordingly.

When you initialize the tableViewController:

[myNSNotificationCentre addObserver:self selector:@selector(updateWithContactDictionary:) name:@"ContactAdded" object:theOtherViewController];

When you add a contact in theOtherViewController:

[myNSNotificationCentre postNotificationName:@"ContactAdded" object:self userInfo:userInfoStoredInAnNSDictionary];

Then as soon as you add an entry, the table will immediately update itself.

Chris Cooper
A: 

Using a notification is a pretty good solution.

Another, which is commonly used in iPhone apps, is to make the original table view the delegate of the "add" view controller (usually presented modally), and have the view controller call an agreed method on its delegate, which will call reloadData and dismiss a modal controller - which is logically best done from the object that presented it in the first place.

Paul Lynch
Well a person from Apple who talked on the CS193P Stanford course did it using delegate so I take that as the best way.
Jonathan