MOBILE

iPhone SDK 3 Programming : XML Processing - An RSS Reader Application

11/13/2013 6:53:48 PM

In this section, we present a working iPhone application based on the code developed so far. The application will present the contents of an RSS feed to the user in a scrollable table view. The complete application can be found in the RSS Reader project in the source downloads.

Listing 1 shows the application delegate declaration and definition. The application delegate uses an instance of the class XORSSFeedNebraska to retrieve the XML document and parse it to generate the items.

Example 1. The RSS reader application delegate declaration and definition.
#import  <UIKit/UIKit.h>
#import "XORSSFeedNebraska.h"
@interface XORSSFeedAppDelegate : NSObject {
UIWindow *window;
UINavigationController *navigationController;
XORSSFeedNebraska *rssFeed;
}
@property (nonatomic, retain)
UINavigationController *navigationController;
@end

#import "XORSSFeedAppDelegate.h"
#import "XORSSFeedNebraska.h"
#import "RootViewController.h"

@implementation XORSSFeedAppDelegate
@synthesize navigationController;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
window =
[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Create the navigation and view controllers
RootViewController *rootViewController =
[[RootViewController alloc] init];
UINavigationController *aNavigationController =
[[UINavigationController alloc]
initWithRootViewController:rootViewController];



self .navigationController = aNavigationController;
[aNavigationController release];
[rootViewController release];
// Configure and show the window
[window addSubview:[navigationController view]];
rssFeed = [[XORSSFeedNebraska alloc] init];
[rssFeed fetchAbsconders];
[window makeKeyAndVisible];
}
-(NSString*)xoTitle{
return @"Nebraska Absconders";
}
- (NSInteger)countOfList {
return [rssFeed numberOfAbsconders];
}
- (id )objectInListAtIndex:(NSUInteger)theIndex {
return [rssFeed absconderAtIndex:theIndex];
}
- (void )dealloc {
[window release];
[navigationController release];
[rssFeed release];
[super dealloc];
}
@end


The delegate's applicationDidFinishLaunching: method creates a window and the table view controller. It then asks the instance of XORSSFeedNebraska to fetch the XML and parse it by calling the fetchAbsconders method. The table view controller's declaration and definition are shown in Listing 2.

Example 2. The RSS reader table controller declaration and definition.
#import <UIKit/UIKit.h>
@interface RootViewController : UITableViewController {
}
@end

#import "RootViewController.h"
#import "XOAbsconder.h"
#import "XORSSFeedAppDelegate.h"
@implementation RootViewController
- init {
if (self = [super init]) {
XORSSFeedAppDelegate *appDelegate =
(XORSSFeedAppDelegate*)[[UIApplication sharedApplication] delegate];
self.title = [appDelegate xoTitle];
}


return self;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
XORSSFeedAppDelegate *appDelegate =
(XORSSFeedAppDelegate*)[[UIApplication sharedApplication] delegate];
return [appDelegate countOfList];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell =
[tableView dequeueReusableCellWithIdentifier:@"XO"];
if (cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"XO"] autorelease];
}
XORSSFeedAppDelegate *appDelegate =
(XORSSFeedAppDelegate*)[[UIApplication sharedApplication] delegate];
XOAbsconder *absconder =
[appDelegate objectInListAtIndex:indexPath.row];
cell.textLabel.text = [absconder description];
return cell;
}
@end

Other  
  •  iPhone SDK 3 Programming : XML Processing - Simple API for XML (SAX)
  •  iPhone SDK 3 Programming : XML Processing - Document Object Model (DOM)
  •  iPhone SDK 3 Programming : XML and RSS
  •  Windows Phone 8 : Making Money - Modifying Your Application, Dealing with Failed Submissions, Using Ads in Your Apps
  •  Windows Phone 8 : Making Money - Submitting Your App (part 3) - After the Submission
  •  Windows Phone 8 : Making Money - Submitting Your App (part 2) - The Submission Process
  •  Windows Phone 8 : Making Money - Submitting Your App (part 1) - Preparing Your Application
  •  Windows Phone 8 : Making Money - What Is the Store?
  •  BlackBerry Push APIs (part 3) - Building an Application that Uses the BlackBerry Push APIs - Checking the Status of a Push Request and Cancelling a Push Request
  •  BlackBerry Push APIs (part 2) - Building an Application that Uses the BlackBerry Push APIs - Unsubscribing From the Push System, Pushing Data to a Subscriber
  •  
    Video tutorials
    - How To Install Windows 8 On VMware Workstation 9

    - How To Install Windows 8

    - How To Install Windows Server 2012

    - How To Disable Windows 8 Metro UI

    - How To Change Account Picture In Windows 8

    - How To Unlock Administrator Account in Windows 8

    - How To Restart, Log Off And Shutdown Windows 8

    - How To Login To Skype Using A Microsoft Account

    - How To Enable Aero Glass Effect In Windows 8

    - How To Disable Windows Update in Windows 8

    - How To Disable Windows 8 Metro UI

    - How To Add Widgets To Windows 8 Lock Screen
    programming4us programming4us
    Top 10
    Free Mobile And Desktop Apps For Accessing Restricted Websites
    MASERATI QUATTROPORTE; DIESEL : Lure of Italian limos
    TOYOTA CAMRY 2; 2.5 : Camry now more comely
    KIA SORENTO 2.2CRDi : Fuel-sipping slugger
    How To Setup, Password Protect & Encrypt Wireless Internet Connection
    Emulate And Run iPad Apps On Windows, Mac OS X & Linux With iPadian
    Backup & Restore Game Progress From Any Game With SaveGameProgress
    Generate A Facebook Timeline Cover Using A Free App
    New App for Women ‘Remix’ Offers Fashion Advice & Style Tips
    SG50 Ferrari F12berlinetta : Prancing Horse for Lion City's 50th