[英]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.