Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.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中使用loadHTMLString:baseURL在UIWebView中加载html字符串?_Html_Iphone_Ios_Uiwebview - Fatal编程技术网

无法在iOS中使用loadHTMLString:baseURL在UIWebView中加载html字符串?

无法在iOS中使用loadHTMLString:baseURL在UIWebView中加载html字符串?,html,iphone,ios,uiwebview,Html,Iphone,Ios,Uiwebview,我正在尝试将youtube视频嵌入到我的iOS应用程序中。为此,我创建了一个UIWebView&尝试从以下位置加载youtube视频 我已经把上述问题的所有答案通读了一遍。即使这样,它也不起作用。 我也尝试过加载非常简单的HTML NSString *embedHTML =[NSString stringWithFormat:@"<html><body>Hello World</body></html>"]; [webView loadHTML

我正在尝试将youtube视频嵌入到我的iOS应用程序中。为此,我创建了一个
UIWebView
&尝试从以下位置加载
youtube
视频

我已经把上述问题的所有答案通读了一遍。即使这样,它也不起作用。 我也尝试过加载非常简单的HTML

 NSString *embedHTML =[NSString stringWithFormat:@"<html><body>Hello World</body></html>"];
 [webView loadHTMLString:embedHTML baseURL:nil];
NSString*embedHTML=[NSString stringWithFormat:@“Hello World”];
[webView loadHTMLString:EmbedHtmlBaseURL:nil];
即使这样,我也会遇到编译错误
Parse-Issue-Expecte']'

我尝试过清理、退出XCode并再次启动它。我不知道,我不能用那种方法。如何对my
UIWebView
使用上述
loadHTMLString
方法


PS:请不要将此问题标记为重复问题。我已经尝试了
Stackoverflow
中的所有解决方案。没有任何效果

如果您希望人们帮助您,您可能需要提供更多代码。我只是以类似的方式使用了webView,它工作得很好

self.webView = [[UIWebView alloc] initWithFrame:myFrame];
self.webView.scalesPageToFit = YES;
[self.webView setBackgroundColor:[UIColor whiteColor]];

//pass the string to the webview
[self.webView loadHTMLString:[[self.itineraryArray objectAtIndex:indexPath.row] valueForKey:@"body"] baseURL:nil];

//add it to the subview
[self.view addSubview:self.webView];

您能提供更多信息和代码吗?

在webview上似乎不是问题。请在代码中断的地方添加代码。错误表明您在代码的某个地方遗漏了一个
]

webview*webDesc=[[UIWebView alloc]initWithFrame:cRectMake(12,50,276,228)];
WebView *webDesc = [[UIWebView alloc]initWithFrame:CGRectMake(12, 50, 276, 228)];

NSString *embedHTML = @"<html><head></head><body><p>1. You agree that you will be the technician servicing this work order?.<br>2. You are comfortable with the scope of work on this work order?.<br>3. You understand that if you go to site and fail to do quality repair for  any reason, you will not be paid?.<br>4. You must dress business casual when going on the work order.</p></body></html>";

webDesc.userInteractionEnabled = NO;
webDesc.opaque = NO;
webDesc.backgroundColor = [UIColor clearColor];
[webDesc loadHTMLString: embedHTML baseURL: nil];
NSString*嵌入HTML=@“1。您同意您将是维护此工单的技术人员?
2。您对本工单的工作范围是否满意?
3。您知道,如果您前往现场,由于任何原因未能进行质量维修,您将不会获得报酬?
4。在办理工单时,您必须穿商务休闲装。

“; webDesc.userInteractionEnabled=否; webDesc.不透明=否; webDesc.backgroundColor=[UIColor clearColor]; [webDesc loadHTMLString:EmbedHtmlBaseURL:nil];
-(NSString*)getHTMLContent
{
NSString*cssPath=[[NSBundle mainBundle]pathForResource:@“baseline”类型:@“css”];
NSData*cssData=[NSData DATA WITH CONTENTS OFFILE:cssPath];
NSString*cssStyle=[[NSString alloc]initWithData:cssData encoding:NSASCIIStringEncoding];
NSDateFormatter*dateFormatter=[[NSDateFormatter alloc]init];
[dateFormatter setDateStyle:nsDateFormatTermeNiumStyle];
NSString*subtitle=[NSString stringWithFormat:@“%@|%@”,self.article.author,[dateFormatter stringFromDate:self.article.publishedDate];
NSString*htmlString=[NSString stringWithFormat:@“%@%@

%@

%@”,cssStyle,self.article.title,subtitle,self.article.content]; 返回htmlString; }
非常简单。只需添加一行即可。请尝试:

NSString *htmlString = @"<html><head></head><body><p>1. You agree that you will be the technician servicing this work order?.<br>2. You are comfortable with the scope of work on this work order?.<br>3. You understand that if you go to site and fail to do quality repair for  any reason, you will not be paid?.<br>4. You must dress business casual when going on the work order.</p></body></html>";
[WebView loadHTMLString: htmlString baseURL: nil];
NSString*htmlString=@“1。您同意您将是维护此工单的技术人员?
2。您对本工单的工作范围是否满意?
3。您知道,如果您前往现场,由于任何原因未能进行质量维修,您将不会获得报酬?
4。在办理工单时,您必须穿商务休闲装。

“; [WebView加载htmlString:htmlString基URL:nil];
尝试将url直接加载到webview中:

 UIWebView *webview=[[UIWebView alloc]initWithFrame:CGRectMake(100, 100, 200, 250)];

[webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://youtube.com/embed/-0Xa4bHcJu8"]]];

这就是我所做的
UIWebView*webView=[[UIWebView alloc]initWithFrame:myFrame];NSString*embedHTML=[NSString stringWithFormat:@“Hello World”];[webView loadHTMLString:embedHTML baseURL:nil]
就是这样,这就是我所做的。我得到了编译时错误。那
loadHTMLString
方法本身不起作用。即使一切正常,它也会显示
解析问题Expecte']'
为编译错误。你确定错误来自webView吗?如果你注释掉webView行,错误就会消失吗?你添加了吗将webview添加到主视图?是的。问题在于webview。如果我对该行进行了注释,则一切正常。即使在添加自身之前,我也会收到错误。除了调试之外,其他都做了吗?记录webview的框架,并请添加它here@LithuT.V..我甚至不能编译代码。这是一个编译时错误mpiles代码?注释
[webView loadHTMLString:EmbedHtmlBaseURL:nil]
line完美地编译了代码。我遇到了同样的错误。你是如何解决的?@LithuT.V..No,不是因为我离开了
]
。我甚至创建了一个新项目&在那里我写了同样的一行。我甚至没有复制粘贴它。我手动键入了所有内容。即使如此,在其他项目中也出现了同样的错误:-(你说的是哪一行?请检查webview框架?同时检查webview是否有有效内存。连接正确。代码似乎正常,表示与问题无关。)
 UIWebView *webview=[[UIWebView alloc]initWithFrame:CGRectMake(100, 100, 200, 250)];

[webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://youtube.com/embed/-0Xa4bHcJu8"]]];