0

我现在有点绝望:/我有一个带有 4 个项目的标签栏控制器。在 4. 选项卡中,我包含了一个显示 pdf 列表的 webView。如果我在 webView 中打开 PDF,则无法通过链接返回主 webView。有没有办法通过重新点击 4. TabBar 来重新加载 View?如果我从 3. 更改为 4. tabbar 它可以工作(viewWillAppear)。

在此处输入图像描述

有人告诉我,以下方法应该有效:

- (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();
}

}

但实际上我不知道应该在哪个文件中插入该方法。(见打印屏幕)

非常感谢你们的帮助!

4

1 回答 1

2
  1. 子类UITabBarController

1.1。Cmd+N 并创建一个新的 NSObject 类实例,并将其命名为 TabBarController

1.2. 在TabBarController.h替换NSObject,以便它读取@interface TabBarController : UITabBarController <UITabBarControllerDelegate>

1.3. 添加TabBarController.m这个:

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

1.4. 和这个

- (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。在 IB,Inspection 中,将 Tab Bar Controller 的类更改为您的 TabBarController(而不是UITabBarController

1.6. 您还需要包含MehrViewController.hTabBarController.m


编辑

在 MehrViewController.m 中(正如您在问题中发布的那样,假设它有一个 webView)

// An example of implementing reloadView
    - (void)reloadView {
       [self.webView reload];
    }
于 2012-03-15T20:14:04.433 回答