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

时间:2012-12-15 10:56:34

标签: iphone objective-c ios ios5 uiwebview

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

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

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

<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

1 个答案:

答案 0 :(得分: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