简体   繁体   English

返回表视图时如何重新加载视图?

[英]How to reload view when returning to a tableview?

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. 我遇到的问题是,当用户进入选项卡选择表视图时,选择一个选项卡,然后返回到主要设置表视图,不会调用-(void)viewDidLoad方法。 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? 当用户返回主设置tableview时,如何调用该方法,或在该新方法中复制该方法中的内容?

Here is the code I currently have in my viewDidLoad method: 这是我当前在viewDidLoad方法中拥有的代码:

- (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. 提前致谢。

use: 采用:

-(void)viewDidAppear:(BOOL)animated {
    [self.tableView reloadData];
}

use. 采用。

-(void)viewWillAppear:(BOOL)animated {
    [self.tableView reloadData];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM