views:

18

answers:

1

So you have UINavigationController, with a parent table which has one cell

---------------
|  paul     > |
---------------

And you click on it and get a screen which has textfields that you enter

---------------
| name: paul  |
---------------
| age: 23     |
---------------
| hair: brown |
---------------
| etc         |
---------------

---------------
| save button |
---------------

When you change the name to Steve, and press the Save button (which pops the view), how do get the initial table to update? I'm using NSUserdefaults to save to and load from. When I pop to the initial view, the name doesn't get changed. ... However, if I restart the app, then it's there.

Can't work out how to update the first table while the app is running.

+2  A: 

Hi

You could either implement the delegate pattern or send an NSNotification. For this I think the amount of code is about the same but since it is one viewController communicating to one other you should go with delegate.

When you instantiate (I assume you present a modalViewController by the way you describe it) the new UIViewController to be pushed, you set the delegate of the childViewController to self(self being the parent viewController). Then you implement a method in the parent that is in the delegate protocol. I.e. - (void) dataChanged:(NSString*) newData. This methods should update the table:

- (void) dataChanged:(NSString*) newData {

    [self.tableView reloadData];
}

When the data is changed in the pushed viewController it calls [self.delegate dataChanged:newData];

This is the pattern Apple used for their components, so if what I just wrote does not make sense, try looking for "delegate pattern" and you will soon be back on track:)

RickiG