Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
UIWebview键盘返回键按下ios 7_Ios_Iphone_Objective C_Uiwebview_Ios7 - Fatal编程技术网

UIWebview键盘返回键按下ios 7

UIWebview键盘返回键按下ios 7,ios,iphone,objective-c,uiwebview,ios7,Ios,Iphone,Objective C,Uiwebview,Ios7,当点击UIWebview的返回键时,我试图找到一个解决方案! 我尝试了以下链接,但它不工作 当用户在UIWebview上键入并按下返回键时,我想做一些偏移工作 这是我正在使用的代码 - (void)viewDidLoad { [super viewDidLoad]; NSString* plainContent = @"Edit here....."; NSString* htmlContentString = [NSString stringWithFormat:

当点击UIWebview的返回键时,我试图找到一个解决方案! 我尝试了以下链接,但它不工作

当用户在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;
}
-(void)viewDidLoad
{
[超级视图下载];
NSString*plainContent=@“在此处编辑…”;
NSString*htmlContentString=[NSString stringWithFormat:
@""
""
""
"%@"
""
“,纯内容];
[_webviewloadhtmlstring:htmlContentString baseURL:nil];
}
-(BOOL)webView:(UIWebView*)aWebView应与request一起加载:(NSURLRequest*)请求导航类型:(UIWebView导航类型)导航类型{
NSString*requestString=[[RequestURL]绝对字符串];
NSArray*components=[requestString componentsSeparatedByString:@]:“;
NSString*任务=(NSString*)[组件对象索引:0];
如果([[[request URL]absoluteString]rangeOfString:@“enterClicked”].location!=NSNotFound)//找到“enterClicked”时
{
NSLog(@“enterClicked!”);
//做你想做的工作
返回否;
}
如果([TheTaskIsequalString:@“returnkeypressed”]){
NSLog(“任务”);
[A视图编辑:是];
返回否;
}
返回YES;
}

文本视图中插入此代码:shouldChangeTextInRange:

if ([text isEqualToString:@"\n"]) {
    [textView resignFirstResponder];
    return NO;
}
为什么这个问题的答案不起作用

我尝试过并为我工作,我只将方法
shouldStartLoadWithRequest:
更改为:

- (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([theTask isEqualToString:@"returnkeypressed"]){
        [aWebView endEditing:YES];
        return NO;
    }
    return YES;
}
另一种方法是使用缓冲区文本视图,如my更改键盘

编辑:您需要添加脚本以检测返回键:

NSString* plainContent = @"Edit here.....";

NSString* htmlContentString = [NSString stringWithFormat:
                               @"<html>"
                                "<head>"
                                    "<script>"
                                        "function returnKeyPressed(event){"
                                            "if(window.event.keyCode == 13)"
                                                "document.location = \"returnkeypressed:\";"
                                            "return true;"
                                        "}"
                                    "</script>"
                                "</head>"
                                "<body onKeyPress=\"return returnKeyPressed(event)\">"
                                    "<div id=\"content\" contenteditable=\"true\" style=\"font-family: Arial\">%@"
                                    "</div>"
                                "</body>"
                               "</html>",
                               plainContent];
NSString*plainContent=@“在此处编辑…”;
NSString*htmlContentString=[NSString stringWithFormat:
@""
""
""
“函数returnKeyPressed(事件){”
“如果(window.event.keyCode==13)”
“document.location=\”返回键按下:\”;“
“返回真值;”
"}"
""
""
""
"%@"
""
""
"",
纯内容];

我已经试过了,发现它不起作用,因为UIWebview只识别DOM。我不确定,但可能是b,因为ios 7。所以请检查我的另一个建议。与此同时,我将在iOS 7上注册。好吧!我不想在webview中添加新的UITextview,因为我也允许在webview中使用图像,就像用户可以添加文本注释,并在webview中添加图像和项目符号一样,一切正常。。。我唯一想做的就是检查用户是否按return键,我必须偏移webview,以避免隐藏文本和更好的UI体验!以上代码在ios 6中也不适用于我!!:(:(@dcorbata)前端可能比本机更容易做到这一点。当光标进入任何输入字段时,在网页末尾插入
可能会让webview滚动。