<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Loading Local Files into UIWebView</title>
	<atom:link href="http://dblog.com.au/iphone-development/loading-local-files-into-uiwebview/feed/" rel="self" type="application/rss+xml" />
	<link>http://dblog.com.au/iphone-development/loading-local-files-into-uiwebview/</link>
	<description>My Development Blog</description>
	<lastBuildDate>Fri, 18 Sep 2009 02:31:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Jesse</title>
		<link>http://dblog.com.au/iphone-development/loading-local-files-into-uiwebview/comment-page-1/#comment-3289</link>
		<dc:creator>Jesse</dc:creator>
		<pubDate>Wed, 05 Aug 2009 17:15:02 +0000</pubDate>
		<guid isPermaLink="false">http://dblog.com.au/?p=96#comment-3289</guid>
		<description>Hey there, I do believe the solution to the image issue is that all images in your application are bundled and appear at the root directory.  In other words, you can have a structure like Resources/html/images/foo.jpg, but when you call that image like so  your app won&#039;t find it - the image in the bundle is at the root level, so only  will work.  This goes for CSS/Javascript etc.  I might be wrong about this, but this http://iphoneincubator.com/blog/windows-views/uiwebview-revisited and this post http://iphoneincubator.com/blog/windows-views/display-images-in-uiwebview seem to corroborate that fact.  If anyone else knows how to creat sub-folders that work, please let us all know! Cheers</description>
		<content:encoded><![CDATA[<p>Hey there, I do believe the solution to the image issue is that all images in your application are bundled and appear at the root directory.  In other words, you can have a structure like Resources/html/images/foo.jpg, but when you call that image like so  your app won&#8217;t find it &#8211; the image in the bundle is at the root level, so only  will work.  This goes for CSS/Javascript etc.  I might be wrong about this, but this <a href="http://iphoneincubator.com/blog/windows-views/uiwebview-revisited" rel="nofollow">http://iphoneincubator.com/blog/windows-views/uiwebview-revisited</a> and this post <a href="http://iphoneincubator.com/blog/windows-views/display-images-in-uiwebview" rel="nofollow">http://iphoneincubator.com/blog/windows-views/display-images-in-uiwebview</a> seem to corroborate that fact.  If anyone else knows how to creat sub-folders that work, please let us all know! Cheers</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dor</title>
		<link>http://dblog.com.au/iphone-development/loading-local-files-into-uiwebview/comment-page-1/#comment-3284</link>
		<dc:creator>Dor</dc:creator>
		<pubDate>Wed, 29 Jul 2009 15:06:25 +0000</pubDate>
		<guid isPermaLink="false">http://dblog.com.au/?p=96#comment-3284</guid>
		<description>I have this code:

NSString *imagePath = [[NSBundle mainBundle] resourcePath];
	imagePath = [imagePath stringByReplacingOccurrencesOfString:@&quot;/&quot; withString:@&quot;//&quot;];
	imagePath = [imagePath stringByReplacingOccurrencesOfString:@&quot; &quot; withString:@&quot;%20&quot;];

	NSString *HTMLData = @&quot;&quot;;
	[webView loadHTMLString:HTMLData baseURL:[NSURL URLWithString: [NSString stringWithFormat:@&quot;file:/%@//&quot;,imagePath]]];

and when i test it, it shows me the small cube with a question mark in it, as it doesn&#039;t find the image.
What am i doing wrong?

thanks</description>
		<content:encoded><![CDATA[<p>I have this code:</p>
<p>NSString *imagePath = [[NSBundle mainBundle] resourcePath];<br />
	imagePath = [imagePath stringByReplacingOccurrencesOfString:@"/" withString:@"//"];<br />
	imagePath = [imagePath stringByReplacingOccurrencesOfString:@" " withString:@"%20"];</p>
<p>	NSString *HTMLData = @&#8221;";<br />
	[webView loadHTMLString:HTMLData baseURL:[NSURL URLWithString: [NSString stringWithFormat:@"file:/%@//",imagePath]]];</p>
<p>and when i test it, it shows me the small cube with a question mark in it, as it doesn&#8217;t find the image.<br />
What am i doing wrong?</p>
<p>thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elijah</title>
		<link>http://dblog.com.au/iphone-development/loading-local-files-into-uiwebview/comment-page-1/#comment-2230</link>
		<dc:creator>Elijah</dc:creator>
		<pubDate>Mon, 06 Apr 2009 07:44:59 +0000</pubDate>
		<guid isPermaLink="false">http://dblog.com.au/?p=96#comment-2230</guid>
		<description>Does anyone know how to load images from the Documents directory?  I tried this and it doesn&#039;t work for Documents...</description>
		<content:encoded><![CDATA[<p>Does anyone know how to load images from the Documents directory?  I tried this and it doesn&#8217;t work for Documents&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rezarazali</title>
		<link>http://dblog.com.au/iphone-development/loading-local-files-into-uiwebview/comment-page-1/#comment-2027</link>
		<dc:creator>rezarazali</dc:creator>
		<pubDate>Sat, 04 Apr 2009 07:46:20 +0000</pubDate>
		<guid isPermaLink="false">http://dblog.com.au/?p=96#comment-2027</guid>
		<description>Add ur html into the .m file itself.

NSString *HTMLData = @&quot;your html shd go here, delete all the whitespace. &quot;;</description>
		<content:encoded><![CDATA[<p>Add ur html into the .m file itself.</p>
<p>NSString *HTMLData = @&#8221;your html shd go here, delete all the whitespace. &#8220;;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: E.C.</title>
		<link>http://dblog.com.au/iphone-development/loading-local-files-into-uiwebview/comment-page-1/#comment-1768</link>
		<dc:creator>E.C.</dc:creator>
		<pubDate>Wed, 01 Apr 2009 17:24:49 +0000</pubDate>
		<guid isPermaLink="false">http://dblog.com.au/?p=96#comment-1768</guid>
		<description>I was able to load a test.html file located locally using UIWebView.  However, I would like to hyperlink other local html (L2.html) from test.html.   I could not get it to work by using a tag in test.html with HREF=&quot;L2.html&quot; . Can anyone help?  
Thank you.</description>
		<content:encoded><![CDATA[<p>I was able to load a test.html file located locally using UIWebView.  However, I would like to hyperlink other local html (L2.html) from test.html.   I could not get it to work by using a tag in test.html with HREF=&#8221;L2.html&#8221; . Can anyone help?<br />
Thank you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Neil Mix</title>
		<link>http://dblog.com.au/iphone-development/loading-local-files-into-uiwebview/comment-page-1/#comment-909</link>
		<dc:creator>Neil Mix</dc:creator>
		<pubDate>Tue, 27 Jan 2009 22:37:00 +0000</pubDate>
		<guid isPermaLink="false">http://dblog.com.au/?p=96#comment-909</guid>
		<description>This may be a bit more convenient:
NSURL *baseURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] resourcePath]];</description>
		<content:encoded><![CDATA[<p>This may be a bit more convenient:<br />
NSURL *baseURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] resourcePath]];</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim</title>
		<link>http://dblog.com.au/iphone-development/loading-local-files-into-uiwebview/comment-page-1/#comment-898</link>
		<dc:creator>Tim</dc:creator>
		<pubDate>Sun, 18 Jan 2009 09:41:00 +0000</pubDate>
		<guid isPermaLink="false">http://dblog.com.au/?p=96#comment-898</guid>
		<description>Thanks, this is helpful!
One things that&#039;s been driving me nuts though. I have images that are 480x320. The bounds of my UIWebView are also those dimensions. But the images shows up much smaller on the iPhone. I think this has something to do with the iPhone shrinking things so that &quot;most&quot; webpages look good on it. But how can I disable this in the context of my UIWebView? I would like to generate content at 480x320 and then load it and have it take the whole screen. 
This has been driving me nuts! Any ideas?

Either way, thanks to all those who posted replies, and especially to the writer of this tutorial!</description>
		<content:encoded><![CDATA[<p>Thanks, this is helpful!<br />
One things that&#8217;s been driving me nuts though. I have images that are 480&#215;320. The bounds of my UIWebView are also those dimensions. But the images shows up much smaller on the iPhone. I think this has something to do with the iPhone shrinking things so that &#8220;most&#8221; webpages look good on it. But how can I disable this in the context of my UIWebView? I would like to generate content at 480&#215;320 and then load it and have it take the whole screen.<br />
This has been driving me nuts! Any ideas?</p>
<p>Either way, thanks to all those who posted replies, and especially to the writer of this tutorial!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter</title>
		<link>http://dblog.com.au/iphone-development/loading-local-files-into-uiwebview/comment-page-1/#comment-875</link>
		<dc:creator>Peter</dc:creator>
		<pubDate>Thu, 18 Dec 2008 15:51:18 +0000</pubDate>
		<guid isPermaLink="false">http://dblog.com.au/?p=96#comment-875</guid>
		<description>These tutorials have been very helpful. However, when I add the code from above to the Web Browser tutorial, it throws the following errors. Do you have any idea on how I might correct?

Thanks.		

/Users/pfavaro/Desktop/WebBrowserTutorial/Classes/WebBrowserTutorialAppDelegate.m:36: error: syntax error before &#039;@&#039; token
		/Users/pfavaro/Desktop/WebBrowserTutorial/Classes/WebBrowserTutorialAppDelegate.m:36: error: syntax error at &#039;OTHER&#039; token
		/Users/pfavaro/Desktop/WebBrowserTutorial/Classes/WebBrowserTutorialAppDelegate.m:38: error: syntax error at &#039;OTHER&#039; token
		/Users/pfavaro/Desktop/WebBrowserTutorial/Classes/WebBrowserTutorialAppDelegate.m:36: warning: unused variable &#039;HTMLData&#039;
Build failed (3 errors, 1 warning)</description>
		<content:encoded><![CDATA[<p>These tutorials have been very helpful. However, when I add the code from above to the Web Browser tutorial, it throws the following errors. Do you have any idea on how I might correct?</p>
<p>Thanks.		</p>
<p>/Users/pfavaro/Desktop/WebBrowserTutorial/Classes/WebBrowserTutorialAppDelegate.m:36: error: syntax error before &#8216;@&#8217; token<br />
		/Users/pfavaro/Desktop/WebBrowserTutorial/Classes/WebBrowserTutorialAppDelegate.m:36: error: syntax error at &#8216;OTHER&#8217; token<br />
		/Users/pfavaro/Desktop/WebBrowserTutorial/Classes/WebBrowserTutorialAppDelegate.m:38: error: syntax error at &#8216;OTHER&#8217; token<br />
		/Users/pfavaro/Desktop/WebBrowserTutorial/Classes/WebBrowserTutorialAppDelegate.m:36: warning: unused variable &#8216;HTMLData&#8217;<br />
Build failed (3 errors, 1 warning)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel</title>
		<link>http://dblog.com.au/iphone-development/loading-local-files-into-uiwebview/comment-page-1/#comment-866</link>
		<dc:creator>Daniel</dc:creator>
		<pubDate>Sun, 07 Dec 2008 20:35:46 +0000</pubDate>
		<guid isPermaLink="false">http://dblog.com.au/?p=96#comment-866</guid>
		<description>Hi again,

I finally got it working to load an image locally (se first post) :)

The problem was the html-code, but this works fine:

&lt;HTML&gt;
&lt;BODY&gt;
&lt;img src=&quot;logo.jpg&quot;&gt;
&lt;/BODY&gt;
&lt;/HTML&gt;

However, I dont have the same luck with loading a sound-file (wav) in the same manner:

&lt;HTML&gt;
&lt;BODY&gt;
&lt;embed src=&quot;test.wav&quot; loop=&quot;false&quot; autoplay=&quot;false&quot; width=&quot;145&quot; height=&quot;60&quot;&gt;&lt;/embed&gt;
&lt;/BODY&gt;
&lt;/HTML&gt;

I thought that the &quot;imagePath&quot; in the code would give you access to other local objects as well, but perhaps I misunderstood?</description>
		<content:encoded><![CDATA[<p>Hi again,</p>
<p>I finally got it working to load an image locally (se first post) <img src='http://dblog.com.au/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>The problem was the html-code, but this works fine:</p>
<p>&lt;HTML&gt;<br />
&lt;BODY&gt;<br />
&lt;img src=&#8221;logo.jpg&#8221;&gt;<br />
&lt;/BODY&gt;<br />
&lt;/HTML&gt;</p>
<p>However, I dont have the same luck with loading a sound-file (wav) in the same manner:</p>
<p>&lt;HTML&gt;<br />
&lt;BODY&gt;<br />
&lt;embed src=&#8221;test.wav&#8221; loop=&#8221;false&#8221; autoplay=&#8221;false&#8221; width=&#8221;145&#8243; height=&#8221;60&#8243;&gt;&lt;/embed&gt;<br />
&lt;/BODY&gt;<br />
&lt;/HTML&gt;</p>
<p>I thought that the &#8220;imagePath&#8221; in the code would give you access to other local objects as well, but perhaps I misunderstood?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Skip Haughay</title>
		<link>http://dblog.com.au/iphone-development/loading-local-files-into-uiwebview/comment-page-1/#comment-737</link>
		<dc:creator>Skip Haughay</dc:creator>
		<pubDate>Sat, 08 Nov 2008 16:02:00 +0000</pubDate>
		<guid isPermaLink="false">http://dblog.com.au/?p=96#comment-737</guid>
		<description>I am trying to figure out the best way to implement some functionality that requires styled text runs within a block of text, presented as part of what stylistically appears as a grouped list view.  Whether or not this is the actual implementation remains to be seen by what we end up being able to actually do with the framework.  I have been having a heck of a time getting this to work this week, so I may have to try a different approach.

Here&#039;s what we are trying to implement:

The screen will contain is a grouped list of four or more items.  TWO of the items are blocks of text, ie. a section entitled Overview and a section entitled Description.  Inside the rounded rectangle item of the particular section there is but one cell.  That cell will contain static text about this item.  What we would LIKE to show in this is richly formatted text.  This is something that is currently not possible with UILabel items.  The secondary requirement is that we want a simple way that a non-programmer (the content expert using this) can edit their own text content for these cells in a layout editor of some sort, and have this information presented in the application at runtime for their customers.  To this end, we thought that perhaps a UIWebView would be the ideal solution.  We might also be able to have a version in which the application pulls the content from a remote web source, which would allow the trainer to customize the content presentation remotely.

And now the fun begins.

So this part of the program is organized as follows:

There is a protocol that defines an abstract interface for a factory class, whose purpose is to create the four various cell types that are required for this particular screen.  There is an instance of a concrete factory created that conforms to this protocol and contains a few required fields.  This is passed into the designated initializer of my subclass of UITableViewController.  This tableview controller conforms to the UITableViewDelegate protocol, so that it can use its factory object to create the required cells, provide group counts, names, etc, and cell size information.

I have for my overview cell defined a subclass of the UITableViewCell, which contains a subview that is a UIWebView.  I&#039;m creating this from a nib, btw.

SO through various contortions, I get the UIWebView supplied with the file URL of the HTML content it needs to display.  It&#039;s just text...

So what I then try to do, or rather what I WANT to do, is have the content loaded, with the width of the UIWebView constrained to the dimensions set in the frame in IB.  I want the height of the UIWebView to grow to whatever height is required to fully render the block of styled text contained in the file.  I setup the HTML with a viewport meta tag that I thought would constrain the width and disable scaling, but am unsure if it actually is working as I wanted it to.

So anyway, the UIWebView delegate gets called when the content is done loading.  What I wanted to do there is constrain the width of the UIWebView, and size the height to that required to show all of the content.  I try doing this by invoking sizeToFit.  Interesting effect, but not quite what I wanted... I can&#039;t figure out how to constrain it, and the UIWebView, despite being contained in the content superview of the cell, is not being CLIPPED to the view of the container.  But that&#039;s another problem.

What I then wanted to do is cause the containing cell to be redrawn and resized to fit the height of the content in the UIWebView.  I tried telling the table view that it needed redisplay, or needed to be layed out again, but neither of these seem to have any effect.  So what I get is an unconstrained UIWebView with the content I want, overrunning the view of the parent container view within the cell.

How to make this work?

First question, I guess, is how to constrain the UIWebView in one direction and then query its height after it has loaded and sized its content.
Second question is, how do I get the tableview to redraw itself and ask for the cell heights again?

I can easily re-architect this so that the UIWebViews are created prior to the table creation, and then when I make the cells in the tableView:cellForRowAtIndexPath, I could size the cell based upon what I know as the size of the UIWebView, and just add it as a subview of the cell&#039;s content view...  But then how do I convert the size of the UIWebView cell, which is in pixels, to points, which is what ableView:heightForRowAtIndexPath: returns?

I could also just NOT do this with a tableview, but rather just lay out my own set of views.  But then the problem still remains, how do we constrain UIWebView in one direction, size it in another direction and then query what that new height is so that the containing view can be sized appropriately?

Furthermore, this view will not always contain just four items.  We could have multiple video placards (which invoke video playback in media player) as well as still image views, diagrams, etc.  The contents are all data-driven, edited via plist goodness, and a sort of &quot;data bundle&quot; which is a hierarchy of folders containing assets, such as HTML for rich text, images, video assets, etc.  In this manner, a non-programmer will be able to customize the content, and not bug me every time they want to modify the product.

So any ideas?  Any idea of a better approach that will meet these requirements?  I can, of course, change the design requirements, but I am a stubborn SOB.</description>
		<content:encoded><![CDATA[<p>I am trying to figure out the best way to implement some functionality that requires styled text runs within a block of text, presented as part of what stylistically appears as a grouped list view.  Whether or not this is the actual implementation remains to be seen by what we end up being able to actually do with the framework.  I have been having a heck of a time getting this to work this week, so I may have to try a different approach.</p>
<p>Here&#8217;s what we are trying to implement:</p>
<p>The screen will contain is a grouped list of four or more items.  TWO of the items are blocks of text, ie. a section entitled Overview and a section entitled Description.  Inside the rounded rectangle item of the particular section there is but one cell.  That cell will contain static text about this item.  What we would LIKE to show in this is richly formatted text.  This is something that is currently not possible with UILabel items.  The secondary requirement is that we want a simple way that a non-programmer (the content expert using this) can edit their own text content for these cells in a layout editor of some sort, and have this information presented in the application at runtime for their customers.  To this end, we thought that perhaps a UIWebView would be the ideal solution.  We might also be able to have a version in which the application pulls the content from a remote web source, which would allow the trainer to customize the content presentation remotely.</p>
<p>And now the fun begins.</p>
<p>So this part of the program is organized as follows:</p>
<p>There is a protocol that defines an abstract interface for a factory class, whose purpose is to create the four various cell types that are required for this particular screen.  There is an instance of a concrete factory created that conforms to this protocol and contains a few required fields.  This is passed into the designated initializer of my subclass of UITableViewController.  This tableview controller conforms to the UITableViewDelegate protocol, so that it can use its factory object to create the required cells, provide group counts, names, etc, and cell size information.</p>
<p>I have for my overview cell defined a subclass of the UITableViewCell, which contains a subview that is a UIWebView.  I&#8217;m creating this from a nib, btw.</p>
<p>SO through various contortions, I get the UIWebView supplied with the file URL of the HTML content it needs to display.  It&#8217;s just text&#8230;</p>
<p>So what I then try to do, or rather what I WANT to do, is have the content loaded, with the width of the UIWebView constrained to the dimensions set in the frame in IB.  I want the height of the UIWebView to grow to whatever height is required to fully render the block of styled text contained in the file.  I setup the HTML with a viewport meta tag that I thought would constrain the width and disable scaling, but am unsure if it actually is working as I wanted it to.</p>
<p>So anyway, the UIWebView delegate gets called when the content is done loading.  What I wanted to do there is constrain the width of the UIWebView, and size the height to that required to show all of the content.  I try doing this by invoking sizeToFit.  Interesting effect, but not quite what I wanted&#8230; I can&#8217;t figure out how to constrain it, and the UIWebView, despite being contained in the content superview of the cell, is not being CLIPPED to the view of the container.  But that&#8217;s another problem.</p>
<p>What I then wanted to do is cause the containing cell to be redrawn and resized to fit the height of the content in the UIWebView.  I tried telling the table view that it needed redisplay, or needed to be layed out again, but neither of these seem to have any effect.  So what I get is an unconstrained UIWebView with the content I want, overrunning the view of the parent container view within the cell.</p>
<p>How to make this work?</p>
<p>First question, I guess, is how to constrain the UIWebView in one direction and then query its height after it has loaded and sized its content.<br />
Second question is, how do I get the tableview to redraw itself and ask for the cell heights again?</p>
<p>I can easily re-architect this so that the UIWebViews are created prior to the table creation, and then when I make the cells in the tableView:cellForRowAtIndexPath, I could size the cell based upon what I know as the size of the UIWebView, and just add it as a subview of the cell&#8217;s content view&#8230;  But then how do I convert the size of the UIWebView cell, which is in pixels, to points, which is what ableView:heightForRowAtIndexPath: returns?</p>
<p>I could also just NOT do this with a tableview, but rather just lay out my own set of views.  But then the problem still remains, how do we constrain UIWebView in one direction, size it in another direction and then query what that new height is so that the containing view can be sized appropriately?</p>
<p>Furthermore, this view will not always contain just four items.  We could have multiple video placards (which invoke video playback in media player) as well as still image views, diagrams, etc.  The contents are all data-driven, edited via plist goodness, and a sort of &#8220;data bundle&#8221; which is a hierarchy of folders containing assets, such as HTML for rich text, images, video assets, etc.  In this manner, a non-programmer will be able to customize the content, and not bug me every time they want to modify the product.</p>
<p>So any ideas?  Any idea of a better approach that will meet these requirements?  I can, of course, change the design requirements, but I am a stubborn SOB.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

