0

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!

joelschmid
  • 828
  • 1
  • 16
  • 32
  • Here is the similar question. There is a tutorial on how to reload the page, by clikcing on the tab. http://stackoverflow.com/questions/9709519/reload-uiview-when-pressing-tab-item-inside-initialized-view/9710060#9710060 – Sierra Alpha Mar 15 '12 at 19:42
  • Thanks! I read through the tutorial but actually I don't know where to add the described code? If you may can have look on the posted printScreen, do you know where i have to add the described implementation? – joelschmid Mar 15 '12 at 19:56

1 Answers1

2
  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];
    }
Sierra Alpha
  • 3,707
  • 4
  • 23
  • 36
  • Hey Canopus! Thank you a lot for your help! I think I almost got it, but sadly just almost, I'm getting a warning right now called: "Instance method '-reloadView' not found (return type defaults to 'id') what does that means? (Sorry to ask that simple questions...) Following you will find a picture of the warning: http://joelschmid.ch/daten/tabbarcontroller.tiff What do I have to do? – joelschmid Mar 20 '12 at 22:59
  • @Schmid -reloadView is method that 'you' have defined in your MehrViewController. You may have a different method, for example -reloadMyWebView. By default, your MehrViewController doesn't have such method. In another word, you have to implement it yourself. I added an example of such implementation as an edit to the answer. – Sierra Alpha Mar 20 '12 at 23:35
  • Hey @Canopus I hope this is the last time I have to bother you! :-) Can you have a look at the PrintScreens in the archive (http://joelschmid.ch/daten/PrintSrciAppReloadWebsite.zip). I think I did everything right, but when i clicked on the TabBarItem the second time the website (webView) doesn't reload. I really would like to reciprocate to you, if you can contact me on my private e-mail (see stackoverflow account). Thanks in advance!!! – joelschmid Mar 21 '12 at 20:30