Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After some googling I have finally found a fitting solution for the question I posed. Hopefully this would help those who face the same problem. </p> <p>The trick is with the formatting of the string path when creating an NSURL object for baseURL of a UIWebView. Although usually I use the typical "Users/...../dir/file" in most cases, loading using UIWebView's loadHTMLString:baseURL needs a different approach. </p> <p>As described in <a href="http://dblog.com.au/iphone-development/loading-local-files-into-uiwebview/" rel="noreferrer">http://dblog.com.au/iphone-development/loading-local-files-into-uiwebview/</a>, where I got the solution, string path to the resources just needs to have slashes to be replaced with double-slashes and spaces with %20:</p> <pre><code>NSString *imagePath = [[NSBundle mainBundle] resourcePath]; imagePath = [imagePath stringByReplacingOccurrencesOfString:@"/" withString:@"//"]; imagePath = [imagePath stringByReplacingOccurrencesOfString:@" " withString:@"%20"]; NSString *HTMLData = @" &lt;h1&gt;Hello this is a test&lt;/h1&gt; &lt;img src="sample.jpg" alt="" width="100" height="100" /&gt;"; [webView loadHTMLString:HTMLData baseURL: [NSURL URLWithString: [NSString stringWithFormat:@"file:/%@//",imagePath] ]]; </code></pre> <p>Do take note of the replacing of the strings and also the:</p> <pre><code>[NSString stringWithFormat:@"file:/%@//",imagePath] </code></pre> <p>Although the example code above is retrieving the path to the mainBundle of the application, it can also work in other folders, ie Documents(and its subfolders) as I did in mine.</p> <p>Kind regards, oonoo</p> <p>PS Thanks again Nic for the reply :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload