-1

I have an app where a user can select the default tab they want loaded when they open the app. I have a settings table view controller that I've created in a storyboard. I have it set to static cells and created a cell that the user can press and uses a push segue to display another tableview with cells that the user can select to select the default tab. On the cell in the main settings table view, I have a label displaying the currently selected tab and the text of that label is set when the view is loaded. The problem I'm having is that when the user goes into the tab selecting table view, selects a tab, then returns to the main settings tableview, the -(void)viewDidLoad method doesn't get called. How can I call that method, or replicate the contents in that method in a new method the is called when the user returns to the main settings tableview?

Here is the code I currently have in my viewDidLoad method:

- (void)viewDidLoad
{
    [super viewDidLoad];


    NSUserDefaults *theDefaults = [NSUserDefaults standardUserDefaults];
    int theInt = [theDefaults integerForKey:@"defTab"];
    NSString *theString;
    switch (theInt) {
        case 0:
            theString = @"Home";
            break;
        case 1:
            theString = @"2D";
            break;
        case 2:
            theString = @"3D";
            break;
        case 3:
            theString = @"Calculator";
            break;
        case 4:
            theString = @"Extras";
            break;
        default:
            break;

    }

currentTabLabel.text = theString;
}

Thanks in advance.

Milo
  • 5,041
  • 7
  • 33
  • 59
  • possible duplicate of [Objective C: How to reload tableview immediately after switching tabs?](http://stackoverflow.com/questions/6398183/objective-c-how-to-reload-tableview-immediately-after-switching-tabs) – wattson12 Jul 13 '13 at 08:20
  • Not even close to the duplicate. Please read the question being asked and look at the one being asked in that post. Then comment with possible duplicates. – Milo Jul 13 '13 at 08:22
  • read the highest rated answer (not the accepted one), seems to suggest the same problem. your question is different but I think the underlying issue is the same – wattson12 Jul 13 '13 at 08:24

2 Answers2

3

use:

-(void)viewDidAppear:(BOOL)animated {
    [self.tableView reloadData];
}
  • Thanks for a nice, clear answer. Unlike some users *cough* @wattson12 – Milo Jul 13 '13 at 08:27
  • 2
    You generally want to call the superclass implementation of these UIViewController methods. E.g., `[super viewDidAppear:animated];` – james_womack Jul 13 '13 at 08:33
0

use.

-(void)viewWillAppear:(BOOL)animated {
    [self.tableView reloadData];
}
dhaya
  • 1,522
  • 13
  • 21