我正在尝试将youtube视频嵌入到我的iOS应用程序中。为此,我创建了一个UIWebView
&尝试加载here
Youtube
视频
我已经完成了上述问题的所有答案。即使这样它也不起作用。 我也试过加载非常简单的HTML
NSString *embedHTML =[NSString stringWithFormat:@"<html><body>Hello World</body></html>"];
[webView loadHTMLString:embedHTML baseURL:nil];
即便如此,我收到编译错误Parse Issue Expecte ']'
我试过清洁,退出XCode&amp;再次重新启动它。我不知道,我无法使用那种方法。如何对我的loadHTMLString
使用上述UIWebView
方法。
PS:请不要将此问题标记为重复。我已尝试Stackoverflow
中的所有解决方案。什么都没有效果
答案 0 :(得分:5)
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];
答案 1 :(得分:1)
- (NSString *)getHTMLContent
{
NSString *cssPath = [[NSBundle mainBundle] pathForResource:@"baseline" ofType:@"css"];
NSData *cssData = [NSData dataWithContentsOfFile:cssPath];
NSString *cssStyle = [[NSString alloc] initWithData:cssData encoding:NSASCIIStringEncoding];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
NSString *subtitle = [NSString stringWithFormat:@"%@ | %@", self.article.author, [dateFormatter stringFromDate:self.article.publishedDate]];
NSString *htmlString = [NSString stringWithFormat:@"<html><head><meta name='viewport' content='width=device-width; initial-scale=1.0; maximum-scale=1.0;'></head><style type=\"text/css\">%@</style><body><div id=\"container\"><h1>%@</h1><p class='subtitle'>%@</p>%@</div></body></html>", cssStyle, self.article.title, subtitle, self.article.content];
return htmlString;
}
答案 2 :(得分:1)
很简单。你只需要添加一行。试一试:
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];
答案 3 :(得分:0)
如果您希望别人帮助您,您可能需要提供更多代码。我只是以类似的方式使用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];
您能提供更多信息和代码吗?
答案 4 :(得分:0)
它似乎不是webview上的一个问题。请在破解时添加代码。错误说你错过了代码中某处的]
答案 5 :(得分:-2)
尝试将网址直接加载到网页视图中:
UIWebView *webview=[[UIWebView alloc]initWithFrame:CGRectMake(100, 100, 200, 250)];
[webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://youtube.com/embed/-0Xa4bHcJu8"]]];