UIWebView的contentEditable图像复制粘贴崩溃(EXC_BAD_ACCESS)

4
我正在一个UIWebView中加载一些html内容。这些内容看起来像这样。
<img alt="" src="/image/968" style="width: 75px; height: 26px;">qweqwwqeqwe<img src="/image/969" width="32" height="32"></p>

这部分内容运行良好。我正在使用从iOS 5.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,要么包含零个对象。希望能够得到任何提示?

enter image description here


@crypticcoder,你用的是我写的同样的代码吗?因为我的代码在这里可以运行。我先测试过,然后再粘贴到这里。 - Prince Kumar Sharma
你能添加崩溃信息吗?(EXC_BAD_ACCESS) - JCurativo
@JennEve 这篇帖子里有一个崩溃信息。 - obenjiro
@crypticcoder 你尝试过在带有Instruments和Zombies模板的模拟器上运行吗?它看起来像是一个典型的过度释放内存问题,比如在自动释放对象上释放。也许你是用[NSString stringWithFormat:]构建HTML字符串,并在稍后释放它了? - Daniel Bauke
@DanielBauke 我已经在Zombies模板中尝试过了。我非常熟悉在zombies模板中使用工具的方法。但是在这个特定的崩溃中,我无法找出任何线索。Instruments/Zombies没有给出任何提示。 - SayeedHussain
显示剩余2条评论
1个回答

2

我使用了以下代码将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,但代码本身是正常工作的。


1
@Ai_boy 在 iPad 模拟器 iOS 5.1 xcode 4.3.2 上复制粘贴图像会导致应用程序崩溃。 - SayeedHussain
@Hercules 在 iPad 模拟器 iOS 5.1 xcode 4.3.2 上复制和粘贴图像会导致应用程序崩溃。 - SayeedHussain

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接