2013-08-29 46 views
1

使用HTML雖然實現web視圖爲我編寫類似下面的越來越怪異的錯誤而在IOS

_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-代碼的頁面,通過更「%」的轉換比數據參數警告在

SRC = \ 「%@ \」

我不知道該怎麼辦,請幫助我。

回答

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 
0

編輯width=\"400\" height=\"700\"width=\"%d\" height=\"%d\"因爲您稍後在構建HTML字符串時傳遞參數。

此外,正如0x7fffffff所述,如果您只是製作一個簡單字符串,那麼請將embedHTML寫爲@"your_string"而不是[NSString stringWithString:@"your_string"]; XCode現在警告此冗餘。

+0

它清除了警告並且非常感謝。 –

+0

你能輸入確切的警告嗎? – CodenameLambda1

+0

哦,是的正確!該死的!我怎麼會錯過它。 – CodenameLambda1

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 
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];