0
votes

I have a tab bar controller connected to several navigation controllers. For one of the navigation controllers, I have a view controller with a web view inside. Everything works perfectly; however, say a user clicks a like within the web view and it takes them to a second page...I want that user to be able to click the tab bar button at the bottom and have it send them back to the original web view. Hopefully that makes sense but as an example, look at the App Store app on your iPhone. Say you click on an app within the Featured page. If you click the Featured tab bar button, it takes the user back to the original page. Below is the code I am using. This is Objective-C.

@property (weak, nonatomic) IBOutlet UIWebView *webView;
@end
@impementation FirstViewController
-(void)viewDidLoad {
   [super viewDidLoad];
   NSURL *url = [NSURL URLWithString:@"www.google.com"]; [self.webView 
      loadRequest:[NSURLRequest requestWithURL:url]];
}
-(void)didReceiveMemoryWarning {
   [super didReceiveMemoryWarning];
}
@end
1
How are you loading this view controller in your UITabViewController's delegate? (e.g. what is the code that is executed when you tap on the tab)Stonz2
Possible duplicate of Go to rootView when tabBar tappedpckill
@pckill it's not quite a dupe, as it involves a web view, rather than popping back to the root VC.Stonz2
Yeah, but reloading the root webpage is trivial. The code for that is even present in the question.pckill

1 Answers

0
votes

As mentioned by @pckill, check out https://stackoverflow.com/a/12142920/1197723
From this, you get the UIViewController that is appearing. From this reference you should be able to call a public method in your presented view controller that shows the home page again. You could do something like, say

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{       
    if([viewController respondsToSelector:@selector(goHome)]){
       [(MyCustomViewController*) viewController goHome];
    }
}

or something along those lines