Question

I'm kinda desperate right now :/ I have a Tab Bar Controller with 4 Items. In the 4. Tab I included a webView which shows a list of pdf's. If I open a PDF in the webView there is no way to go back to the main webView with the links. Is there a way by re-clicking the 4. TabBar to reload the View? If I change from the 3. to the 4. tabbar it works (viewWillAppear).

enter image description here

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!

Was it helpful?

Solution

  1. Subclass UITabBarController

1.1. Cmd+N and create a new instance of NSObject class, and name it TabBarController

1.2. in TabBarController.h replace NSObject so that it reads @interface TabBarController : UITabBarController <UITabBarControllerDelegate>

1.3. in TabBarController.m add this:

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

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. In IB, Inspection, change the class of Tab Bar Controller to your TabBarController (instead of UITabBarController)

1.6. You also need to include MehrViewController.h in TabBarController.m


Edit

in MehrViewController.m (as you posted in your question, assuming it has a webView)

// An example of implementing reloadView
    - (void)reloadView {
       [self.webView reload];
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top