私はiPhone開発者の初心者ですが、
UIWebview に Web ページを読み込んでいますが、
ユーザーが任意のテキストを選択したときに読み込みが完了した後、そのテキストを取得したいのですが、
これが私のコードスニペットです。
- (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);
}
しかし、テキストを選択してもログには何も表示されません。
どんな助けでも大歓迎です。