0
我是新来的iPhone开发者获取文本,从一个UIWebView
我加载在我UIWebView的网页,
装载步骤完成后,当用户选择的任何文本,然后我想获取该文本,
这里是我的代码片段,
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect webFrame = CGRectMake(0.0, 0.0, 500.0, 500.0);
webView = [[UIWebView alloc] initWithFrame:webFrame];
[webView setBackgroundColor:[UIColor greenColor]];
NSString *urlAddress = @"http://stackoverflow.com/";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
[self.view addSubview:webView];
NSString *t= [webView stringByEvaluatingJavaScriptFromString:@"window.getSelection().toString()"];
NSLog(@"selected text=%@",t);
}
,但我的日志显示没事的时候我选择的任何文本。
任何帮助将不胜感激。
不工作,我的日志仍然没有显示。 – Krunal 2012-07-20 06:23:49