Skip to content

Commit

Permalink
Added demo project to show usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Perry authored and David Perry committed May 7, 2011
1 parent 3d54ff9 commit 23b65ea
Show file tree
Hide file tree
Showing 18 changed files with 1,510 additions and 0 deletions.
481 changes: 481 additions & 0 deletions Demo/Demo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions Demo/Demo/Demo-Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>com.xmlreader.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSMainNibFile</key>
<string>MainWindow</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
14 changes: 14 additions & 0 deletions Demo/Demo/Demo-Prefix.pch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// Prefix header for all source files of the 'Demo' target in the 'Demo' project
//

#import <Availability.h>

#ifndef __IPHONE_3_0
#warning "This project uses features only available in iPhone SDK 3.0 and later."
#endif

#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
21 changes: 21 additions & 0 deletions Demo/Demo/DemoAppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// DemoAppDelegate.h
// Demo
//
// Created by David Perry on 07/05/2011.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>

@class DemoViewController;

@interface DemoAppDelegate : NSObject <UIApplicationDelegate> {

}

@property (nonatomic, retain) IBOutlet UIWindow *window;

@property (nonatomic, retain) IBOutlet DemoViewController *viewController;

@end
75 changes: 75 additions & 0 deletions Demo/Demo/DemoAppDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//
// DemoAppDelegate.m
// Demo
//
// Created by David Perry on 07/05/2011.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "DemoAppDelegate.h"

#import "DemoViewController.h"

@implementation DemoAppDelegate


@synthesize window=_window;

@synthesize viewController=_viewController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.

self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
/*
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
*/
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
/*
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
*/
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
/*
Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
*/
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
/*
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
*/
}

- (void)applicationWillTerminate:(UIApplication *)application
{
/*
Called when the application is about to terminate.
Save data if appropriate.
See also applicationDidEnterBackground:.
*/
}

- (void)dealloc
{
[_window release];
[_viewController release];
[super dealloc];
}

@end
19 changes: 19 additions & 0 deletions Demo/Demo/DemoViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// DemoViewController.h
// Demo
//
// Created by David Perry on 07/05/2011.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface DemoViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
NSDictionary *_xmlDictionary;
UITableView *_tableView;
}

@property (nonatomic, retain) IBOutlet UITableView *tableView;

@end
98 changes: 98 additions & 0 deletions Demo/Demo/DemoViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
//
// DemoViewController.m
// Demo
//
// Created by David Perry on 07/05/2011.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "DemoViewController.h"
#import "XMLReader.h"

@implementation DemoViewController

@synthesize tableView=_tableView;

- (void)dealloc
{
[_tableView release];
[_xmlDictionary release];

[super dealloc];
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
[super viewDidLoad];

// Grab some XML data from Twitter
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://twitter.com/status/user_timeline/github"]];

NSError *error = nil;
NSURLResponse *response = nil;

// Synchronous isn't ideal, but simplifies the code for the Demo
NSData *xmlData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

// Parse the XML Data into an NSDictionary
_xmlDictionary = [[XMLReader dictionaryForXMLData:xmlData error:&error] retain];

[self.tableView reloadData];
}

- (void)viewDidUnload
{
[super viewDidUnload];

self.tableView = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}

#pragma mark - UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[_xmlDictionary retrieveForPath:@"statuses.status"] count];
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return @"@github status feed";
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"StatusCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier] autorelease];
cell.textLabel.font = [UIFont systemFontOfSize:12];
cell.textLabel.numberOfLines = 2;
cell.detailTextLabel.font = [UIFont systemFontOfSize:10];
cell.selectionStyle = UITableViewCellEditingStyleNone;
}

// Get the 'status' for the relevant row
NSDictionary *status = [_xmlDictionary retrieveForPath:[NSString stringWithFormat:@"statuses.status.%d", indexPath.row]];

cell.textLabel.text = [status objectForKey:@"text"];
cell.detailTextLabel.text = [status objectForKey:@"created_at"];

return cell;
}

@end
Loading

0 comments on commit 23b65ea

Please sign in to comment.