Graphics Programs Reference
In-Depth Information
UIWebView
In addition to its title, an
RSSItem
also keeps a link that points to the web page where the
post lives. It would be neat if
Nerdfeed
could open up
Safari
and navigate to that page. It
would be even neater if
Nerdfeed
could render that web page without having to leave
Nerd-
feed
to open
Safari
. Good news ? it can using the class
UIWebView
.
Instances of
UIWebView
render web content. In fact, the
Safari
application on your device
uses a
UIWebView
to render its web content. In this part of the chapter, you will create a
view controller whose view is an instance of
UIWebView
. When one of the items is selec-
ted from the table view of
RSSItem
s, you will push the web view's controller onto the
navigation stack and have it load the link stored in the
RSSItem
.
Create a new
NSObject
subclass and name it
WebViewController
. In
We-
bViewController.h
, add a property (but not an instance variable) and change the su-
perclass to
UIViewController
:
@interface WebViewController : NSObject
@interface WebViewController : UIViewController
@property (nonatomic, readonly) UIWebView *webView;
@end
In
WebViewController.m
, override
loadView
to create an instance of
UIWebView
as the view of this view controller. Also, implement the method
webView
to return that
view.
@implementation WebViewController
- (void)loadView
{
// Create an instance of UIWebView as large as the screen
CGRect screenFrame = [[UIScreen mainScreen] applicationFrame];
UIWebView *wv = [[UIWebView alloc] initWithFrame:screenFrame];
// Tell web view to scale web content to fit within bounds of webview
[wv setScalesPageToFit:YES];
[self setView:wv];
}
- (UIWebView *)webView
{
return (UIWebView *)[self view];
}
In
ListViewController.h
, add a new property to
ListViewController
.