how do I get the title of a URL
I have a URL and I will show the URL inside a ModalViewController. I would like to set the开发者_如何学JAVA title of this URL in the navigation bar.
Inside the ModalViewController I have a UIWebView to display the site. Is there a way to extract the title of this site via UIWebView? Did a bit of research and it seems that I would like to use some javascript inside the (void)webViewDidFinishLoad:(UIWebView *)webView
Not sure though how it works.
Try this:
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
NSString* title = [webView stringByEvaluatingJavaScriptFromString: @"document.title"];
navbar.title = title;
}
Taken from: http://blog.mcohen.me/2008/12/12/getting-the-title-of-a-web-view-in-cocoa-touch/
精彩评论