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

标签 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 开始支持的 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

最佳答案

我使用以下代码将 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,而代码工作正常。

关于iphone - UIWebView contentEditable 图像复制粘贴崩溃 (EXC_BAD_ACCESS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13891553/

相关文章:

iphone - 第二次尝试时,viewDidAppear 在 CellForRowAtIndex 之后加载

ios - 无法从 iCloud 迁移永久存储

ios - 使用 UITableView 处理事件

objective-c - 使用应用程序沙箱的 Cocoa 应用程序中的 NSOpenPanel 给出错误

objective-c - 检测 Ctrl + Return 或 Ctrl + Enter 按下

objective-c - 异常[NSNull isEqualToString:]:当我单击calloutAccessoryControlTapped时无法识别的选择器

ios - 如何在iOS中使用AVAsset合并多个视频?

iphone - 如果用户在文本字段为空时按下提交按钮,则摇动 UIAlertView

iphone - 在 map View 上单击图钉时显示联系人姓名

iphone - 使用 AccessToken 从 TabBarViewController 注销到 UIViewController