Reputation: 2689
My app has a tab view controller as the main access point. However, when it runs for the first time, I need to check for some basic data, and if that is missing, I need to show a view to capture this information first . The table in the tab view uses this information to display the data.
The way I am doing it is like this: In my app-delegate, I show the tab view. Then check for information x. If not present, add subview view2 and show it on top. In view2, I capture the information, and on click of a button remove it from superview. The required data is stored in global variables in the model. Now, the control goes back to the tab view which showed it. The problem is that I need to reload the table data in the tab view so that it reflects the correct information. However, I am not able to capture this in my parent tab view. So, the only way I can do a refresh is by manually clicking a button, which is not ideal. I want it to automatically refresh as soon as the subview is removed from the stack.
Upvotes: 2
Views: 847
Reputation: 50697
Registering and calling notifications is the way to go.
For the view you want to send the notification:
- (void) viewDidLoad {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateView:) name:@"updateView" object:nil];
}
- (void)updateView:(NSNotification *)notification {
/* this is where the updates will take place,
such as a [tableView reloadData];
*/
}
And to call that notification:
[[NSNotificationCenter defaultCenter] postNotificationName:@"updateView" object:nil];
Upvotes: 5
Reputation: 39905
One way would be to subclass your parent view and override willRemoveSubview:. This is called just before a view is removed from its superview.
Upvotes: 1
Reputation: 16636
A great way to do this is to have your model post a notification when the new data is added to it. Your table view controller can listen for that notification, and when it receives it, can reload its data.
Check out Apple's explanations of Posting a Notification and Registering for a Notification.
Upvotes: 4