如何启用“全选”在iPhone应用程序的UIWebView? [英] How to enable "select all" in UIWebView in an IPhone App?

查看:140
本文介绍了如何启用“全选”在iPhone应用程序的UIWebView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个嵌入UIWebView的iPhone应用程序。有各种类似于Safari的功能,例如导航等。我正在寻找的任务之一是当用户选择Web视图上的一段文本时呈现全选选项。目前,我只看到复制选项。有没有简单的方法来启用全选菜单项?我当然尝试将一个菜单项添加到共享菜单控制器,但这并不一定实现原始的safari全选功能。任何帮助和指针都非常有用。

I am writing an IPhone application which embeds a UIWebView. There are various safari like features like navigation, etc. One of the tasks I am looking for is to present a "select all" option when the user selects on a piece of text on the web view. Currently, I only see a "copy" option. Is there an easy way to enable the "select all" menu item? I have ofcourse tried adding a menu item to the shared menu controller but that doesn't necessarily implement the original safari "select all" functionality. Any help and pointers will be very useful.

提前致谢。

推荐答案

简短的回答是否定的,这是不可能的。

The short answer is no, this is not possible.

你可以通过继承UIWebView并覆盖(不自行添加任何东西到菜单控制器)来做到这一点:

You could do this by subclassing UIWebView and overriding (without adding anythings to the menu controller yourself):

-(BOOL) canPerformAction:(SEL)action withSender:(id)sender 

并检查选择器是否 selectAll:

喜欢这样:

-(BOOL) canPerformAction:(SEL)action withSender:(id)sender {
    if (action == @selector(selectAll:)) {
        return YES;
    } else {
        return [super canPerformAction:action withSender:sender];
    }
}

这将显示Hold菜单上的Select All选项。然而,这不是webView的默认行为,虽然当您按全选时应用程序不会崩溃,按下它将无效。

This will show the Select All option on the Hold Menu. However this isn't default behaviour of a webView, and while the app won't crash when you press Select All, pressing it will just do nothing.

你可以'甚至创建一个selectAll方法,然后在webview中选择所有内容,因为javascript方法 .select()在Mobile Safari / UIWebView上不起作用。

You can't even create a selectAll method, and then select everything in webview, because the javascript method .select() doesn't work on Mobile Safari/UIWebView.

这篇关于如何启用“全选”在iPhone应用程序的UIWebView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆