Browse files

Implement a web view to display the contents of the link in an RSS item

  • Loading branch information...
1 parent 1bc98b9 commit a6b95d1e7947e595bae3fb3dd40d186a39d4ce2b Ryan Blunden committed Jan 17, 2013
View
3 Nerdfeed/Nerdfeed/ListViewController.h
@@ -8,6 +8,7 @@
#import <Foundation/Foundation.h>
@class RSSChannel;
+@class WebViewController;
@interface ListViewController : UITableViewController <NSURLConnectionDelegate, NSURLConnectionDataDelegate, NSXMLParserDelegate> {
@@ -17,6 +18,8 @@
RSSChannel *channel;
}
+@property(nonatomic, strong) WebViewController *webViewController;
+
- (void)fetchEntries;
@end
View
22 Nerdfeed/Nerdfeed/ListViewController.m
@@ -8,6 +8,7 @@
#import "ListViewController.h"
#import "RSSChannel.h"
#import "RSSItem.h"
+#import "WebViewController.h"
@implementation ListViewController {
@@ -40,6 +41,27 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
return cell;
}
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
+ // Push the web view controller onto the navigation stack - this implicitly creates the web view controller's view
+ // the first time through
+ [[self navigationController] pushViewController:_webViewController animated:YES];
+
+ // Grab the selected item
+ RSSItem *entry = [channel items][[indexPath row]];
+
+ // Construct a URL with the link string of the item
+ NSURL *url = [NSURL URLWithString:[entry link]];
+
+ // Construct a request object with that URL
+ NSURLRequest *req = [NSURLRequest requestWithURL:url];
+
+ // Load the request into the web view
+ [[_webViewController webView] loadRequest:req];
+
+ // Set the title of the web view controller's navigation item
+ [[_webViewController navigationItem] setTitle:[entry title]];
+}
+
- (void)fetchEntries {
// Create a new data container for the stuff service data
xmlData = [[NSMutableData alloc] init];
View
4 Nerdfeed/Nerdfeed/NerdfeedAppDelegate.m
@@ -8,6 +8,7 @@
#import "NerdfeedAppDelegate.h"
#import "ListViewController.h"
+#import "WebViewController.h"
@implementation NerdfeedAppDelegate
@@ -19,6 +20,9 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
UINavigationController *masterNav = [[UINavigationController alloc] initWithRootViewController:lvc];
+ WebViewController *wvc = [[WebViewController alloc] init];
+ [lvc setWebViewController:wvc];
+
[[self window] setRootViewController:masterNav];
self.window.backgroundColor = [UIColor whiteColor];
View
15 Nerdfeed/Nerdfeed/WebViewController.h
@@ -0,0 +1,15 @@
+//
+// Created by rblunden on 1/17/13.
+//
+// To change the template use AppCode | Preferences | File Templates.
+//
+
+
+#import <Foundation/Foundation.h>
+
+
+@interface WebViewController : UIViewController <UIPageViewControllerDelegate>
+
+@property(nonatomic, readonly, strong) UIWebView *webView;
+
+@end
View
29 Nerdfeed/Nerdfeed/WebViewController.m
@@ -0,0 +1,29 @@
+//
+// Created by rblunden on 1/17/13.
+//
+// To change the template use AppCode | Preferences | File Templates.
+//
+
+
+#import "WebViewController.h"
+
+
+@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];
+
+ // Tel the web view to scale web content to fit within the bounds of the webview
+ [wv setScalesPageToFit:YES];
+
+ [self setView:wv];
+}
+
+- (UIWebView *)webView {
+ return (UIWebView *) [self view];
+}
+@end

0 comments on commit a6b95d1

Please sign in to comment.