简体   繁体   中英

Tab Bar / Navigation Refresh

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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