Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS在资源中加载本地映像,并在<;img src=';%@'&燃气轮机;_Ios_Objective C_Iphone_Uiwebview - Fatal编程技术网

iOS在资源中加载本地映像,并在<;img src=';%@'&燃气轮机;

iOS在资源中加载本地映像,并在<;img src=';%@'&燃气轮机;,ios,objective-c,iphone,uiwebview,Ios,Objective C,Iphone,Uiwebview,我想在iOS中加载本地资源映像,但未能在应用程序中显示(但当我登录时,链接已显示)。 这是我的密码 NSBundle* myBundle = [NSBundle mainBundle]; NSString* imgurl = [myBundle pathForResource:@"list-gotit" ofType:@"png"]; htmltext = [NSString stringWithFormat:@"<html><img src='%@'></htm

我想在iOS中加载本地资源映像,但未能在应用程序中显示(但当我登录时,链接已显示)。
这是我的密码

NSBundle* myBundle = [NSBundle mainBundle];
NSString* imgurl = [myBundle pathForResource:@"list-gotit" ofType:@"png"];

htmltext = [NSString stringWithFormat:@"<html><img src='%@'></html>",
                imgurl];

[self.postview loadHTMLString:htmltext baseURL:baseurl];    
NSBundle*myBundle=[NSBundle mainBundle];
NSString*imgurl=[myBundle pathForResource:@“list GoIt”类型:@“png”];
htmltext=[NSString stringWithFormat:@”“,
imgurl];
[self.postview loadHTMLString:htmltext baseURL:baseURL];
img src将加载我的数据/我的url已经正确(我使用NSLOG):


但不显示为图像


谢谢你的帮助。

我想你错过了
中的
/

我做了一个测试:

NSBundle* myBundle = [NSBundle mainBundle];
NSURL *imgUrl = [NSURL fileURLWithPath:[myBundle pathForResource:@"list-gotit" ofType:@"png"]];

NSString *htmltext = [NSString stringWithFormat:@"<html><img src='%@'></html>",
            imgUrl];

self.postview = [[UIWebView alloc] initWithFrame:CGRectMake(100, 100, 300, 300)];
[self.view addSubview:self.postview];
[self.postview loadHTMLString:htmltext baseURL:nil];  
NSBundle*myBundle=[NSBundle mainBundle];
NSURL*imgUrl=[NSURL fileURLWithPath:[myBundle pathForResource:@“list GoIt”,其类型为@“png”];
NSString*htmltext=[NSString stringWithFormat:@',
imgUrl];
self.postview=[[UIWebView alloc]initWithFrame:CGRectMake(100100300300)];
[self.view addSubview:self.postview];
[self.postview loadHTMLString:htmltext baseURL:nil];

一切都好

这对我有用:

 NSString *filePath = [[NSBundle mainBundle] pathForResource:@"list-gotit" ofType:@"png"];
 NSURL    *imageURL = [NSURL fileURLWithPath:filePath];
 NSString *absoluteURLString = [imageURL absoluteString];
 [html appendFormat:@"<img src=\"%@\" />", absoluteURLString];
NSString*filePath=[[NSBundle mainBundle]pathForResource:@“list gotit”,类型为:@“png”];
NSURL*imageURL=[NSURL fileURLWithPath:filePath];
NSString*absoluteURLString=[imageURL absoluteString];
[html appendFormat:@',absoluteURLString];
或作为两个班轮:

NSString *imageURL = [[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"list-gotit" ofType:@"png"]] absoluteString];
[html appendFormat:@"<img src=\"%@\" />", imageURL];
NSString*imageURL=[[NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@“png”]]absoluteString]类型的“list gotit”;
[html格式:@“”,图像URL];

您只需更改以下代码即可

htmltext = [NSString stringWithFormat:@"<html><img src=\"%@\"></html>",
                imgurl];
htmltext=[NSString stringWithFormat:@”“,
imgurl];

这是因为“%@”您的代码不起作用,使用“%@”可能会对您有所帮助。

对不起,我已经这样做了,但也没有显示图像。只有路径图像的链接相同,它没有显示为图像,但链接已经正确。我不能这样做,显示错误“绝对字符串应为:'抱歉,缺少括号。我编辑了我的答案。它显示一个url,但不显示为图像它不是
NSString*imageURL
,它是
NSURL*imageURL
不,它不是。您错过了
absoluteString
呼叫。(返回一个
NSString
对象)
NSString *imageURL = [[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"list-gotit" ofType:@"png"]] absoluteString];
[html appendFormat:@"<img src=\"%@\" />", imageURL];
htmltext = [NSString stringWithFormat:@"<html><img src=\"%@\"></html>",
                imgurl];