<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Chris Danielson&#039;s Blog &#187; UIWebView</title>
	<atom:link href="http://www.chrisdanielson.com/tag/uiwebview/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chrisdanielson.com</link>
	<description>Trials and Tribulations of a Software Developer</description>
	<lastBuildDate>Wed, 14 Sep 2011 00:00:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Apple iPhone Web Kit with Activity Indicator</title>
		<link>http://www.chrisdanielson.com/2009/12/04/apple-iphone-web-kit-with-activity-indicator/</link>
		<comments>http://www.chrisdanielson.com/2009/12/04/apple-iphone-web-kit-with-activity-indicator/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 16:38:43 +0000</pubDate>
		<dc:creator>Chris Danielson</dc:creator>
				<category><![CDATA[iPhone Development]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[UIActivityIndicatorView]]></category>
		<category><![CDATA[UIWebView]]></category>
		<category><![CDATA[Web Kit]]></category>
		<category><![CDATA[WebKit]]></category>

		<guid isPermaLink="false">http://www.chrisdanielson.com/?p=290</guid>
		<description><![CDATA[Welcome to the club of searching for an overly simple UIWebView a.k.a. WebKit example! In this example, I&#8217;ll show you simply how to hand code a quick UIWebView into your program as well as to add a UIActivityIndicatorView a.k.a. an activity indicator. Without jabbing Apple too hard here, the documentation is pretty bad and that [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome to the club of searching for an overly simple UIWebView a.k.a. WebKit example!  In this example, I&#8217;ll show you simply how to hand code a quick UIWebView into your program as well as to add a UIActivityIndicatorView a.k.a. an activity indicator.  Without jabbing Apple too hard here, the documentation is pretty bad and that is why it&#8217;s nice to have an example just shown to you as-is.  I hope this example helps shine a light on the situation for anyone wanting to implement a nice and quick Apple iPhone WebKit solution.</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p290code3'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2903"><td class="code" id="p290code3"><pre class="objc" style="font-family:monospace;">&nbsp;
<span style="color: #6e371a;">#import &lt;UIKit/UIKit.h&gt;</span>
&nbsp;
<span style="color: #a61390;">@interface</span> FirstViewController <span style="color: #002200;">:</span> UIViewController &lt;UIWebViewDelegate&gt;
<span style="color: #002200;">&#123;</span>
	UIWebView <span style="color: #002200;">*</span>myWebView;
	UIActivityIndicatorView <span style="color: #002200;">*</span>activityIndicator;	
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p290code4'); return false;">View Code</a> OBJC</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2904"><td class="code" id="p290code4"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">/*
Inside the @implementation FirstViewController ... 
*/</span>
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>viewDidLoad <span style="color: #002200;">&#123;</span> <span style="color: #11740a; font-style: italic;">//We have a NIB file in play here, so I dropped the loadView here.  Just make sure that your loadView is not getting called twice!</span>
    <span style="color: #002200;">&#91;</span>super viewDidLoad<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>self loadView<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>loadView <span style="color: #002200;">&#123;</span>
	UIView <span style="color: #002200;">*</span>contentView <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIView alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIScreen mainScreen<span style="color: #002200;">&#93;</span> applicationFrame<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
	self.view <span style="color: #002200;">=</span> contentView;	
&nbsp;
	CGRect webFrame <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIScreen mainScreen<span style="color: #002200;">&#93;</span> applicationFrame<span style="color: #002200;">&#93;</span>;
	webFrame.origin.y <span style="color: #002200;">=</span> 0.0f;
	myWebView <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIWebView alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>webFrame<span style="color: #002200;">&#93;</span>;
	myWebView.backgroundColor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIColor blueColor<span style="color: #002200;">&#93;</span>;
	myWebView.scalesPageToFit <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;
	myWebView.autoresizingMask <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight<span style="color: #002200;">&#41;</span>;
	myWebView.delegate <span style="color: #002200;">=</span> self;
	<span style="color: #002200;">&#91;</span>self.view addSubview<span style="color: #002200;">:</span> myWebView<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>myWebView loadRequest<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURLRequest_Class/"><span style="color: #400080;">NSURLRequest</span></a> requestWithURL<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/"><span style="color: #400080;">NSURL</span></a> URLWithString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;http://www.maxpowersoft.com/&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
	activityIndicator <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIActivityIndicatorView alloc<span style="color: #002200;">&#93;</span>initWithActivityIndicatorStyle<span style="color: #002200;">:</span>UIActivityIndicatorViewStyleGray<span style="color: #002200;">&#93;</span>;
	activityIndicator.frame <span style="color: #002200;">=</span> CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0.0</span>, <span style="color: #2400d9;">0.0</span>, <span style="color: #2400d9;">40.0</span>, <span style="color: #2400d9;">40.0</span><span style="color: #002200;">&#41;</span>;
	activityIndicator.center <span style="color: #002200;">=</span> self.view.center;
	<span style="color: #002200;">&#91;</span>self.view addSubview<span style="color: #002200;">:</span> activityIndicator<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>dealloc <span style="color: #002200;">&#123;</span>
	<span style="color: #002200;">&#91;</span>activityIndicator release<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>myWebView release<span style="color: #002200;">&#93;</span>;
        <span style="color: #002200;">&#91;</span>super dealloc<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #6e371a;">#pragma mark WEBVIEW Methods</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>webViewDidStartLoad<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIWebView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>webView
<span style="color: #002200;">&#123;</span>
	<span style="color: #11740a; font-style: italic;">// starting the load, show the activity indicator in the status bar</span>
	<span style="color: #002200;">&#91;</span>UIApplication sharedApplication<span style="color: #002200;">&#93;</span>.networkActivityIndicatorVisible <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;
	<span style="color: #002200;">&#91;</span>activityIndicator startAnimating<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>webViewDidFinishLoad<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIWebView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>webView
<span style="color: #002200;">&#123;</span>
	<span style="color: #11740a; font-style: italic;">// finished loading, hide the activity indicator in the status bar</span>
	<span style="color: #002200;">&#91;</span>UIApplication sharedApplication<span style="color: #002200;">&#93;</span>.networkActivityIndicatorVisible <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
	<span style="color: #002200;">&#91;</span>activityIndicator stopAnimating<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>webView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIWebView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>webView didFailLoadWithError<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSError_Class/"><span style="color: #400080;">NSError</span></a> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>error
<span style="color: #002200;">&#123;</span>
	<span style="color: #11740a; font-style: italic;">// load error, hide the activity indicator in the status bar</span>
	<span style="color: #002200;">&#91;</span>UIApplication sharedApplication<span style="color: #002200;">&#93;</span>.networkActivityIndicatorVisible <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// report the error inside the webview</span>
	<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a><span style="color: #002200;">*</span> errorString <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> stringWithFormat<span style="color: #002200;">:</span>
							 <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&lt;html&gt;&lt;center&gt;&lt;br /&gt;&lt;br /&gt;&lt;font size=+5 color='red'&gt;Error&lt;br /&gt;&lt;br /&gt;Your request %@&lt;/font&gt;&lt;/center&gt;&lt;/html&gt;&quot;</span>,
							 error.localizedDescription<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>myWebView loadHTMLString<span style="color: #002200;">:</span>errorString baseURL<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>That is all there is to it.  It&#8217;s really simple as you can see.  Feel free to copy and paste accordingly.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisdanielson.com/2009/12/04/apple-iphone-web-kit-with-activity-indicator/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>

