**更新**为什么我的图像没有显示在我的UIWebView弹出框中?

时间:2013-06-17 22:58:04

标签: html core-data ios6

我有一个iPad应用程序(XCode 4.6,iOS 6.2,CoreData,ARC和Storyboards)。在CoreData商店中,我有一个图像。

我已将图像写入iPad上的tmp目录。这是代码:

    //  create a temporary file to hold the image
NSString *tmpDir = NSTemporaryDirectory();
UIImage *custImage = [UIImage imageWithData:client.aClientImage];  //  get the image
[UIImagePNGRepresentation(custImage) writeToFile:tmpDir atomically:YES];  //  write the image to tmp/file

// Create file manager
NSError *error;
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSLog(@"\n\ntmp directory: %@", [fileMgr contentsOfDirectoryAtPath:tmpDir error:&error]);

NSLog什么都没显示!

我有一个UIPopover,我在其中显示一些包含图像的数据。我可以从我的CoreData商店获取图像,但在我的HTML中,它没有显示出来。这是我的HTML:

    NSString *htmlString = [NSString stringWithFormat:NSLocalizedString(@"<html> \n"
                        "<head> \n"
                        "<style type=\"text/css\"> \n"
                        "body {font-family: \"Verdana\"; font-size: 12;}\n"  //  font family and font size here
                        "</style> \n"
                        "</head> \n"
                        "<body><h2>%@ %@</h2>"
                        "<p>email: %@<p>phone: %@<p>services: %@<p><img src=\"%@\"/>"  
                        "</body> \n"
                        "</html>",nil),
                        client.aClientFirstName,
                        client.aClientLastName,
                        client.aClientEMail,
                        client.aClientPrimaryPhone,
                        appt.aServices,
                        @"tmpDir/custImage"];

知道图片没有显示的原因吗?

1 个答案:

答案 0 :(得分:2)

问题是您尝试使用<img>元素,但是您使用可转换核心数据属性的值填充其src属性。这些方法的工作方式不同 - img期望指向图片的网址,并且您的属性提供UIImage

处理此问题最直接的方法是将图像写入文件,然后在该文件中生成img标记点。

假设您可以正确使用格式,您也可以使用<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAM0AAAD..."之类的内容而不是您拥有的内容来完成此项工作。您可能想要原始未转换的NSData对象而不是UIImage。这可能需要更多工作,但避免编写临时图像文件。

相关问题