I have a storyboard with a UIViewController. Inside this view, I’ve placed a custom UIWebView. In the code in my custom webview I would like to change the title in navigation control of its outer UIViewController.
I’ve tried to call the superview in the webview, but that just gives me an UIView. How can I, from this webview, change the title in the UIViewController?
Here’s what you do:
In the
UIViewController, I assume that you’ve got some code setup to represent this UIWebView? Add theUIWebViewas a property of theUIViewController(Don’t forget the IBOutlet part!)@property (nonatomic, retain) IBOutlet UIWebView *webView;In the storyboard, link the
UIWebViewto theUIViewController.Make the
UIViewControlleraUIWebViewDelegate(see documentationhere)In the UIViewController, implement the
webViewDidFinishLoad:method. In this method, the UIWebView will let the UIViewController know when it’s done loading the page. You can then assign the title of the webview to the UINavigationController’s title with this code:NSString *pageTitle=[self.webView stringByEvaluatingJavaScriptFromString:@"document.title"];[self.navigationItem setTitle:pageTitle];