Skip to content

Commit

Permalink
Show a list of Gowalla spots around my current location and show chec…
Browse files Browse the repository at this point in the history
…kins upon touching
  • Loading branch information
aaronbrethorst committed Sep 5, 2011
1 parent 1dad4ad commit d5bf1f1
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 8 deletions.
6 changes: 6 additions & 0 deletions GowallaExample/GowallaExample.xcodeproj/project.pbxproj
Expand Up @@ -31,6 +31,7 @@
9305C05714147AD50052A06F /* JSONKit.m in Sources */ = {isa = PBXBuildFile; fileRef = 9305C03E14147AD50052A06F /* JSONKit.m */; };
9305C05A14147AF90052A06F /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 9305C05914147AF90052A06F /* libz.dylib */; };
9305C06014147DB20052A06F /* SpotsTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9305C05F14147DB20052A06F /* SpotsTableViewController.m */; };
9305C0631414804A0052A06F /* CheckinsTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9305C0621414804A0052A06F /* CheckinsTableViewController.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -78,6 +79,8 @@
9305C05914147AF90052A06F /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; };
9305C05E14147DB20052A06F /* SpotsTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SpotsTableViewController.h; sourceTree = "<group>"; };
9305C05F14147DB20052A06F /* SpotsTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SpotsTableViewController.m; sourceTree = "<group>"; };
9305C0611414804A0052A06F /* CheckinsTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CheckinsTableViewController.h; sourceTree = "<group>"; };
9305C0621414804A0052A06F /* CheckinsTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CheckinsTableViewController.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -223,6 +226,8 @@
children = (
9305C05E14147DB20052A06F /* SpotsTableViewController.h */,
9305C05F14147DB20052A06F /* SpotsTableViewController.m */,
9305C0611414804A0052A06F /* CheckinsTableViewController.h */,
9305C0621414804A0052A06F /* CheckinsTableViewController.m */,
);
path = "View Controllers";
sourceTree = "<group>";
Expand Down Expand Up @@ -307,6 +312,7 @@
9305C01514147A860052A06F /* UIImageView+AFNetworking.m in Sources */,
9305C05714147AD50052A06F /* JSONKit.m in Sources */,
9305C06014147DB20052A06F /* SpotsTableViewController.m in Sources */,
9305C0631414804A0052A06F /* CheckinsTableViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
2 changes: 2 additions & 0 deletions GowallaExample/GowallaExample/GowallaExampleAppDelegate.m
Expand Up @@ -8,6 +8,7 @@

#import "GowallaExampleAppDelegate.h"
#import "SpotsTableViewController.h"
#import "CheckinsTableViewController.h"

@implementation GowallaExampleAppDelegate

Expand All @@ -16,6 +17,7 @@ @implementation GowallaExampleAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[ABRouter sharedRouter] registerURLPattern:@"/spots/:spot_id/events" forViewControllerClass:[CheckinsTableViewController class]];
self.spotsTableViewController = [[[SpotsTableViewController alloc] initWithStyle:UITableViewStylePlain] autorelease];
self.navigationController = [[[UINavigationController alloc] initWithRootViewController:self.spotsTableViewController] autorelease];
[self.window addSubview:self.navigationController.view];
Expand Down
@@ -0,0 +1,14 @@
//
// CheckinsTableViewController.h
// GowallaExample
//
// Created by Aaron Brethorst on 9/4/11.
// Copyright 2011 Structlab LLC. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface CheckinsTableViewController : UITableViewController <Routable>
@property(nonatomic,retain) NSMutableArray *tableData;
@property(nonatomic,retain) NSString *apiPath;
@end
@@ -0,0 +1,93 @@
//
// CheckinsTableViewController.m
// GowallaExample
//
// Created by Aaron Brethorst on 9/4/11.
// Copyright 2011 Structlab LLC. All rights reserved.
//

#import "CheckinsTableViewController.h"

@implementation CheckinsTableViewController
@synthesize tableData;
@synthesize apiPath;

- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self)
{
self.title = @"Checkins";
}
return self;
}

- (void)dealloc
{
self.apiPath = nil;
[super dealloc];
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
[super viewDidLoad];

self.tableData = [[[NSMutableArray alloc] init] autorelease];

[[AFGowallaAPIClient sharedClient] getPath:self.apiPath parameters:nil success:^(id response) {

[self.tableData removeAllObjects];
[self.tableData addObjectsFromArray:[response objectForKey:@"activity"]];
[self.tableView reloadData];
}];
}

- (void)viewDidUnload
{
[super viewDidUnload];
self.tableData = nil;
}

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.tableData count];
}

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

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

NSDictionary *activity = [self.tableData objectAtIndex:indexPath.row];

NSString *activityType = [activity objectForKey:@"type"];
NSString *activityUser = [[activity objectForKey:@"user"] objectForKey:@"first_name"];

cell.textLabel.text = [NSString stringWithFormat:@"%@ by %@", activityType, activityUser];

return cell;
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
*/
}

@end
Expand Up @@ -80,14 +80,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
*/
NSDictionary *dict = [self.tableData objectAtIndex:indexPath.row];
[[ABRouter sharedRouter] navigateTo:[dict objectForKey:@"activity_url"] withNavigationController:self.navigationController];
}

@end

0 comments on commit d5bf1f1

Please sign in to comment.