【问题标题】:UIWebView contentEditable image copy paste crash (EXC_BAD_ACCESS)UIWebView contentEditable 图像复制粘贴崩溃 (EXC_BAD_ACCESS)
【发布时间】:2012-12-03 05:08:48
【问题描述】:

我正在UIWebView 中加载一些 html 内容。内容看起来像这样

<img alt="" src="/image/968" style="width: 75px; height: 26px;">qweqwwqeqwe<img src="/image/969" width="32" height="32"></p>

这部分工作正常。我正在使用从 iOS5.0 开始支持的 UIWebViewcontentEditable 属性。我将内容包装在

<div contentEditable="true">mycontent</div>.

我能够编写/复制文本等。但是当我尝试从webView 选择和复制图像并将其粘贴到下一行时,我的应用程序崩溃了 (EXC_BAD_ACCESS)。我在 iPad 1 上运行 iOS 5.1.1。我尝试过检查

 [[UIPasteboard generalPasteboard] image]
 [[UIPasteboard generalPasteboard] images]

 [[UIPasteboard generalPasteboard] url]
 [[UIPasteboard generalPasteboard] urls]

但在我复制图像并检查它们之后,它们总是null 或包含零对象。任何指针将不胜感激?

【问题讨论】:

  • 您在哪里将对象写入粘贴板?显示该代码。
  • @RamyAlZuhouri 我不会将对象写入粘贴板,我认为当我使用标注复制某些内容时,操作系统会进行写入。但我对粘贴板上写的内容不感兴趣。我只是把它放在问题中,因为我认为这可能有助于解决我的问题。我的问题是:当我尝试从 contentEditable UIWebView 中复制粘贴图像时,为什么我的应用程序崩溃了,该 UIWebView 中加载了 html 中的图像?
  • @crypticcoder 你有没有使用我写过的相同代码,因为我的代码在这里工作。我先测试了,然后贴在这里。
  • 可以添加崩溃信息吗? (EXC_BAD_ACCESS)
  • @JennEve 有一个崩溃消息附加到帖子..

标签: iphone objective-c ios ios5 uiwebview


【解决方案1】:

我已使用以下代码将 html 字符串加载到 webView 并对其进行编辑。 它运行良好。

#import "WebViewEditViewController.h"

@interface WebViewEditViewController ()

@end

@implementation WebViewEditViewController

- (void)viewDidLoad
{
 NSString *path = [[NSBundle mainBundle] bundlePath];
 NSURL *baseURL = [NSURL fileURLWithPath:path];

 NSString *htmlString=@"<html><body><div contentEditable=\"true\"><img alt=\"\" src=\"1.jpg\" style=\"width: 100px; height: 100px;\">qweqwwqeqwe<img src=\"2.jpg\" width=\"150px\" height=\"70px\"></p></div></body></html>";
 [_webView loadHTMLString:htmlString baseURL:baseURL];
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

我尝试在复制后打印日志,发现[[UIPasteboard generalPasteboard] image] 在两种情况下都在粘贴null,而代码工作正常。

【讨论】:

  • @Ai_boy 复制和粘贴图像会使 iPad Simulator iOS 5.1 xcode 4.3.2 上的应用程序崩溃。
  • @Hercules 复制和粘贴图像会使 iPad Simulator iOS 5.1 xcode 4.3.2 上的应用程序崩溃。
猜你喜欢
  • 2010-11-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-29
  • 1970-01-01
  • 2013-05-13
  • 1970-01-01
  • 2021-01-19
相关资源
最近更新 更多