views:

28

answers:

3

I have an application where I was using buttons on a toolbar to call up the views, but I am switching it over to using a tab bar.

When using the buttons I was using the following code in MainViewController.m to update the values on the page and it was working just fine:

-(IBAction) loadSummaryView:(id) sender {
 [self clearView];
 [self.view insertSubview:summaryViewController.view atIndex:0];
 //Update the values on the Summary view
[summaryViewController updateSummaryData];
[summaryViewController calculateData];
}

However, with the Tab Bar I can not figure out how to do this. I tried putting all of the necessary code in the Summary Views viewDidLoad and it loads the initial values, but it will not update the values when I change them in another view.

Any help is appreciated. I am a bit new at this, so please don't be cryptic as I may not understand the response.

Thank you.

+1  A: 

By placing your code in viewDidLoad, it will only be called when the view is loaded from the nib. Unless you're running low on memory, this view will remain loaded for the duration of the life of your app.

So if you need to update values every time the view will appear, consider moving that code to an override of viewWillAppear

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    // your stuff goes here...
    [self updateSummaryData];
    [self calculateData];
}
coastwise
+1  A: 

You can update your current view in the viewWillAppear:animated message of the view:

If you have everything setup correctly, there is nothing to do, the UITabBarController will show your view, an your UIViewController will receive a viewWillAppear message, where you can do your update:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    [self updateSummaryData];
    [self calculateData];
}

I strongly recommend reading the View Controller Programming Guide for iOS which describes in detail the main interface paradigms supported by the iPhone.

David
A: 

Thank you both for the answer.

I implemented the code and it is working well.

I also appreciate the link to the UITabBar class reference.