简体   繁体   English

每次单击标签栏项时,如何刷新视图?

[英]How can i refresh a view every time when a tab bar item is clicked?

I am making an application with TabBar. 我正在用TabBar制作一个应用程序。 But TabBarController is not RootViewController. 但是TabBarController不是RootViewController。 In the Tab Bar there are 4 tabs. 在标签栏中有4个标签。 One of those tabs is history which is linked with a table view which shows history. 其中一个选项卡是历史记录,它与显示历史记录的表格视图相关联。 I want to refresh that view every time when i click that so that i can get updated tableview. 我想每次单击时刷新该视图,以便我可以获得更新的tableview。 How can i do that? 我怎样才能做到这一点? Thanks in advance. 提前致谢。

use - (void) viewWillAppear:(BOOL)animated to update any content in your view. use - (void) viewWillAppear:(BOOL)animated更新视图中的任何内容。

- (void) viewWillAppear:(BOOL)animated {
   [super viewWillAppear:animated];
   // You code here to update the view.
}

This method will be called every time the view is about to be displayed. 每次要显示视图时都会调用此方法。

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:YES];
    if ([Globals sharedInstance].isFromFindSimiler)
    {
        [self.view addSubview:_findSimilerView];
        [_historyTableView setFrame:CGRectMake(0, 85, 320, 490)];

    }
    else
    {

    [self history_webservice];
    }
}

I have achieved this. 我做到了这一点。 In this case, whenever user tabs on History screen I call web service for history and update tableview. 在这种情况下,每当“历史记录”屏幕上的用户标签出现时,我都会调用Web服务以获取历史记

instead of using (void)ViewDidLoad use viewWillAppear:(BOOL)animated 而不是使用(void)ViewDidLoad使用viewWillAppear:(BOOL)animated

- (void) viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    //your code 
}

below code added plz ^^ 下面的代码添加了plz ^^

If you change a tabBarIndex, At the same time -(void)viewWillAppear called. 如果更改tabBarIndex,同时 - (void)调用viewWillAppear。

-(void)viewWillAppear:(BOOL)animated
{
    // force the tableview to load
    [tableView reloadData];
}

refer a Apple Sample Code: that is amazing great tutorial for you about UITabBarController http://developer.apple.com/library/ios/#samplecode/TheElements/Introduction/Intro.html 参考Apple示例代码:对于UITabBarController来说,这是一个非常棒的教程http://developer.apple.com/library/ios/#samplecode/TheElements/Introduction/Intro.html

Apple Sample Code is no added [super viewWillAppear:animated]; 没有添加Apple示例代码[super viewWillAppear:animated];

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

相关问题 单击选项卡栏项时如何显示导航栏 - How to display Navigation bar when tab bar item clicked 选择自定义选项卡栏项并选择未选中的透明选项卡项时如何使用 - How can i use custom tab bar item when it's selected and a transparent one it's not selected 单击选项卡栏项时显示覆盖菜单-iOS - Showing a overlaying menu when tab bar item is clicked - IOS 如何将视图分配给标签栏项? - How to assign a view to a tab bar item? 如何从标签栏项触发动作? - How can I trigger an action from a tab bar item? 每次从标签栏按下标签时,如何执行方法? - How do I execute a method every time a tab is pressed from the tab bar? 如何在标签栏应用程序中放置可编辑的表格视图? - How can I put an editable table view in a tab bar application? 用户退出时如何保存当前标签栏项目,并在重新启动时重新加载到该项目? - How do I save current tab bar item when user quits and reload to that item when restart? iPhone-每次我们从一个选项卡切换到另一个选项卡时如何获取主视图(第一视图) - iPhone- How to get the main view (1st view) every time when we switching form one tab to another tab 如何判断哪个标签栏项触发了视图? - How to tell which Tab Bar Item triggers a View?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM