1

在页面中实现 web 视图时,我编写了如下代码

 _testURLString = @"http://192.168.4.196/course/Course";
NSString *embedHTML = [NSString stringWithFormat:@"\
                       <html><head>\
                       <style type=\"text/css\">\
                       body {\
                       background-color: transparent;\
                       color: blue;\
                       }\
                       </style>\
                       </head><body style=\"margin:0\">\
                       <embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
                       width=\"400\" height=\"700\"></embed>\
                       </body></html>"];
NSString *html = [NSString stringWithFormat:embedHTML, _testURLString, 400, 700];

UIWebView *videoView = [[UIWebView alloc] initWithFrame:frame];

videoView.backgroundColor = [UIColor clearColor];
[videoView loadHTMLString:html baseURL:nil];
[self.view addSubview:videoView];

X-code 的警告是比数据参数警告更多的 '%' 转换

src=\"%@\"

我不知道该怎么办请帮助我。

4

4 回答 4

1

您正在使用stringWithFormat:,并且此方法应该替换src=\"%@\"为另一个字符串,但您没有传递任何字符串。

它应该是这样的:

NSString *embedHTML = [NSString stringWithFormat:@"\
                   <html><head>\
                   <style type=\"text/css\">\
                   body {\
                   background-color: transparent;\
                   color: blue;\
                   }\
                   </style>\
                   </head><body style=\"margin:0\">\
                   <embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
                   width=\"400\" height=\"700\"></embed>\
                   </body></html>", _testURLString]; //or something else
于 2013-08-29T13:37:05.150 回答
0

您可以完全消除第二个格式化字符串,因为它实际上并没有做任何有价值的事情。此外,您从未在初始格式化字符串中添加 URL 格式说明符和视频的宽度/高度。这是一个例子:

NSString *embedHTML = [NSString stringWithFormat:@"\
                       <html><head>\
                       <style type=\"text/css\">\
                       body {\
                       background-color: transparent;\
                       color: blue;\
                       }\
                       </style>\
                       </head><body style=\"margin:0\">\
                       <embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
                       width=\"%i\" height=\"%i\"></embed>\
                       </body></html>",_testURLString,400,700];
于 2013-08-29T13:37:51.773 回答
0

编辑width=\"400\" height=\"700\"为,width=\"%d\" height=\"%d\"因为您稍后会在构建 HTML 字符串时传递参数。

此外,正如 0x7fffffff 所说,如果你只是制作一个简单的字符串,那么现在写你的embedHTMLas@"your_string"而不是[NSString stringWithString:@"your_string"];XCode 会警告这种冗余。

于 2013-08-29T13:34:11.233 回答
0

您需要(src=\"%@\")在此字符串中传递 src 值。有关更多信息,请参见最后一行

 NSString *embedHTML = [NSString stringWithFormat:@"\
                           <html><head>\
                           <style type=\"text/css\">\
                           body {\
                           background-color: transparent;\
                           color: blue;\
                           }\
                           </style>\
                           </head><body style=\"margin:0\">\
                           <embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
                           width=\"400\" height=\"700\"></embed>\
                           </body></html>",_testURLString];     // Edited  
于 2013-08-29T13:36:20.957 回答