简体   繁体   English

标签栏更改后重新加载页面

[英]Reload the page after tabbar change

I am using a masterdetail app inside a tab bar controller. 我在标签栏控制器中使用masterdetail应用。 From one tab, i am collecting some data and using 从一个选项卡,我正在收集一些数据并使用

tabBarController.selectedIndex=0;

This goes to the first tab which has the masterview controller. 这将转到具有masterview控制器的第一个选项卡。 However, i have updated the database in my third tab and the table contents have to be updated in the master detail app of first tab. 但是,我已经在第三个选项卡中更新了数据库,并且必须在第一个选项卡的主详细信息应用程序中更新表内容。 Effectively i need to call the 实际上,我需要致电

viewDidLoad

of the master detail app after setting the selected index. 设置选定索引后,主详细信息应用程序的设置。 Could anyone say how to do this. 谁能说出该怎么做。

用新方法重写viewDidLoad的内容,然后在viewWillAppear上调用它们。

There are a few ways to accomplish this. 有几种方法可以完成此操作。

  • Change your code in the 1st tab to update when your view appears instead of loads (recommended method) 在第一个标签中更改代码以在显示视图而不是加载视图时进行更新(推荐方法)

  • Call the view method of the controller to force the viewDidLoad if you have a reference to the controller. 如果对控制器有引用,则调用控制器的view方法以强制viewDidLoad。

     [self.localFundraiserController view]; 
  • Use notifications. 使用通知。 In your 3rd tab after the user has entered some data, send a notification. 用户输入一些数据后,在第3个标签中,发送通知。 In your first tab, look for notifications and respond. 在第一个标签中,查找通知并做出响应。

     //1st tab controller: -(void)viewDidLoad { [self loadUserData:nil] [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loadUserData:) name:@"kUserEnteredData" object:nil]; } -(void)loadUserData:(NSNotification*)notification { id userData = notification.object; } //3rd tab controller when user entered data [[NSNotificationCenter defaultCenter] postNotificationName:@"kUserEnteredData" object:userData]; 

When posting the notification, you can pass object data which would be read in your loadUserData method. 发布通知时,可以传递将在loadUserData方法中读取的对象数据。 This is optional. 这是可选的。 The problem with notifications is that there is no guarantee that the view in your first tab is still loaded, so it may not be able to respond to the notification. 通知的问题在于,不能保证第一个选项卡中的视图仍然处于加载状态,因此它可能无法响应通知。

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

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