简体   繁体   English

单击TabBarItem重新加载ViewController

[英]Reload ViewController by clicking on TabBarItem

I'm kinda desperate right now :/ I have a Tab Bar Controller with 4 Items. 我现在有点绝望:/我有一个带有4个项目的标签栏控制器。 In the 4. Tab I included a webView which shows a list of pdf's. 在4.选项卡中,我包含了一个显示pdf列表的webView。 If I open a PDF in the webView there is no way to go back to the main webView with the links. 如果我在webView中打开PDF,则无法使用链接返回主webView。 Is there a way by re-clicking the 4. TabBar to reload the View? 有没有办法重新点击4. TabBar重新加载视图? If I change from the 3. to the 4. tabbar it works (viewWillAppear). 如果我从3.更改为4. tabbar它可以工作(viewWillAppear)。

在此输入图像描述

Someone told me, that the following method should work: 有人告诉我,以下方法应该有效:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
if ([viewController isKindOfClass:[UIColor class]]) {
    //Try this if you're pushing the webView in another ViewController
    [viewController.navigationController popToRootViewControllerAnimated:YES];
    //or access to your webView and call goBack();
}

} }

but actually I have no idea in which file I should insert that method. 但实际上我不知道我应该在哪个文件中插入该方法。 (See print Screen) (见打印屏幕)

Thanks a LOT in advance for your help guys! 非常感谢您的帮助!

  1. Subclass UITabBarController 子类UITabBarController

1.1. 1.1。 Cmd+N and create a new instance of NSObject class, and name it TabBarController Cmd + N并创建一个NSObject类的新实例,并将其命名为TabBarController

1.2. 1.2。 in TabBarController.h replace NSObject so that it reads @interface TabBarController : UITabBarController <UITabBarControllerDelegate> TabBarController.h替换NSObject以便它读取@interface TabBarController : UITabBarController <UITabBarControllerDelegate>

1.3. 1.3。 in TabBarController.m add this: TabBarController.m添加:

- (id) init
{
  self = [super init];
  if (self) 
  {
    self.delegate = self;
  }
  return self;
}

1.4. 1.4。 and this 和这个

- (void)tabBarController:(UITabBarController *)tabBarController 
    didSelectViewController:(UIViewController *)viewController
{
  // Is this the view controller type you are interested in?
  if ([viewController isKindOfClass:[MehrViewController class]])
  {
    // call appropriate method on the class, e.g. updateView or reloadView
    [(MehrViewController *) viewController updateView];
  }
}

1.5. 1.5。 In IB, Inspection, change the class of Tab Bar Controller to your TabBarController (instead of UITabBarController ) 在IB,检查,类标签栏控制器更改TabBarController (代替UITabBarController

1.6. 1.6。 You also need to include MehrViewController.h in TabBarController.m 您还需要在TabBarController.m包含MehrViewController.h


Edit 编辑

in MehrViewController.m (as you posted in your question, assuming it has a webView) 在MehrViewController.m中(正如您在问题中发布的那样,假设它有一个webView)

 // An example of implementing reloadView - (void)reloadView { [self.webView reload]; } 

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

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