views:

273

answers:

1

In this iphone app I'm trying to make it so that when you select a table cell it saves that action, pops the current view controller and calls the previous view controller (which is and always will be a TableView) to reload it's cells with new data.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//update data code here
[self.navigationController popViewControllerAnimated:TRUE];
//Here is where I want the code to reload the view [parentTableView reload]; or something }

That's what I have at the moment when you select a cell in the current Table View

+6  A: 

You need need to send -reloadData to the UITableView:

[tableView reloadData];

Edit : So just to clarify, you have a parent UITableViewController which pushes a child UITableViewController onto the navigationController? The code in your sample is implemented in the didSelectRowAtIndexPath in the child view controller?

If this is the case, you need to to add a property to your child UITableViewController which stores a pointer to its parent. Make sure this isn't a reference counted property because that will result in a circular reference. So before you pop your child UITableViewController it can send -reloadData to the tableView property of its parent.

Cannonade
Thanks @NSResponder :). Still not quite there with my Objective-C vernacular.
Cannonade
How would I get a reference to the previous tabelView though? I want the page you are going to to reload not the one you are leaving when you pop it off the navigation stack.
Affian
I solved it by passing a target and selector to the new view that works as a callback, also later on I was able to use a `NSNotification` to tell it to update when new data was avaliable
Affian