【发布时间】:2013-12-02 04:53:09
【问题描述】:
我正在尝试在单击 UIWebview 的返回键时找出解决方案! 我尝试了以下链接,但它不起作用!
UIWebView, customize "return" key
How to detect keyboard enter key?
当用户在 UIWebview 上键入并按下返回键时,我想做一些偏移工作!
这是我正在使用的代码!
- (void)viewDidLoad
{
[super viewDidLoad];
NSString* plainContent = @"Edit here.....";
NSString* htmlContentString = [NSString stringWithFormat:
@"<html>"
"<body>"
"<div id=\"content\" contenteditable=\"true\" style=\"font-family: Arial\">"
"%@"
"</div>"
"</body></html>", plainContent];
[_webview loadHTMLString:htmlContentString baseURL:nil];
}
- (BOOL)webView:(UIWebView*)aWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType{
NSString *requestString = [[request URL] absoluteString];
NSArray *components = [requestString componentsSeparatedByString:@":"];
NSString *theTask = (NSString *)[components objectAtIndex:0];
if([[[request URL] absoluteString] rangeOfString:@"enterClicked"].location!=NSNotFound) // When "enterClicked" found
{
NSLog(@"enterClicked !");
//Do your desired work
return NO;
}
if([theTask isEqualToString:@"returnkeypressed"]){
NSLog(@"theTask");
[aWebView endEditing:YES];
return NO;
}
return YES;
}
【问题讨论】:
标签: ios iphone objective-c uiwebview ios7