开发者

how do I get the title of a URL

开发者 https://www.devze.com 2023-03-09 10:42 出处:网络
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.

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/

0

精彩评论

暂无评论...
验证码 换一张
取 消