Permalink
Browse files

tableview is now updated with dates from json

  • Loading branch information...
1 parent 868af6e commit 95105d92900229609b42be0147b98b73e9e43865 @matsimitsu committed Jan 22, 2011
Showing with 922 additions and 351 deletions.
  1. +0 −23 Classes/BroadcastCalendar.h
  2. +0 −62 Classes/BroadcastCalendar.m
  3. +5 −1 Classes/BroadcastDate.h
  4. +35 −0 Classes/BroadcastDate.m
  5. +7 −10 Classes/RootViewController.m
  6. BIN build/Debug-iphonesimulator/iTrakt.app.dSYM/Contents/Resources/DWARF/iTrakt
  7. BIN build/Debug-iphonesimulator/iTrakt.app/MainWindow.nib
  8. BIN build/Debug-iphonesimulator/iTrakt.app/RootViewController.nib
  9. BIN build/Debug-iphonesimulator/iTrakt.app/iTrakt
  10. BIN build/iTrakt.build/Debug-iphonesimulator/iTrakt.build/Objects-normal/i386/BroadcastCalendar.o
  11. BIN build/iTrakt.build/Debug-iphonesimulator/iTrakt.build/Objects-normal/i386/BroadcastDate.o
  12. BIN build/iTrakt.build/Debug-iphonesimulator/iTrakt.build/Objects-normal/i386/RootViewController.o
  13. +0 −1 build/iTrakt.build/Debug-iphonesimulator/iTrakt.build/Objects-normal/i386/iTrakt.LinkFileList
  14. +200 −129 build/iTrakt.build/Debug-iphonesimulator/iTrakt.build/build-state.dat
  15. BIN build/iTrakt.build/Debug-iphonesimulator/iTrakt.build/iTrakt-project-headers.hmap
  16. +11 −9 build/iTrakt.build/Debug-iphonesimulator/iTrakt.build/iTrakt.dep
  17. BIN build/iTrakt.build/Debug-iphonesimulator/iTrakt.build/iTrakt.hmap
  18. BIN build/iTrakt.build/iTrakt.pbxindex/cdecls.pbxbtree
  19. BIN build/iTrakt.build/iTrakt.pbxindex/decls.pbxbtree
  20. BIN build/iTrakt.build/iTrakt.pbxindex/files.pbxbtree
  21. BIN build/iTrakt.build/iTrakt.pbxindex/imports.pbxbtree
  22. BIN build/iTrakt.build/iTrakt.pbxindex/pbxindex.header
  23. BIN build/iTrakt.build/iTrakt.pbxindex/protocols.pbxbtree
  24. BIN build/iTrakt.build/iTrakt.pbxindex/refs.pbxbtree
  25. BIN build/iTrakt.build/iTrakt.pbxindex/strings.pbxstrings/control
  26. BIN build/iTrakt.build/iTrakt.pbxindex/strings.pbxstrings/strings
  27. BIN build/iTrakt.build/iTrakt.pbxindex/subclasses.pbxbtree
  28. BIN build/iTrakt.build/iTrakt.pbxindex/symbols0.pbxsymbols
  29. +0 −6 iTrakt.xcodeproj/project.pbxproj
  30. +73 −45 iTrakt.xcodeproj/robertbeekman.mode1v3
  31. +591 −65 iTrakt.xcodeproj/robertbeekman.pbxuser
@@ -1,23 +0,0 @@
-//
-// BroadcastCalendar.h
-// iTrakt
-//
-// Created by Robert Beekman on 21-01-11.
-// Copyright 2011 __MyCompanyName__. All rights reserved.
-//
-
-#import <Foundation/Foundation.h>
-#include <HTTPRiot/HTTPRiot.h>
-
-
-@interface BroadcastCalendar : HRRestModel {
- NSString *username;
- NSArray *broadcastDates;
-}
-
-@property (retain) NSString *username;
-@property (retain) NSArray *broadcastDates;
-
-- (id)initWithDates:(NSArray *)broadcastDates;
-
-@end
@@ -1,62 +0,0 @@
-//
-// BroadcastCalendar.m
-// iTrakt
-//
-// Created by Robert Beekman on 21-01-11.
-// Copyright 2011 __MyCompanyName__. All rights reserved.
-//
-
-#import "BroadcastCalendar.h"
-#include <HTTPRiot/HTTPRiot.h>
-
-@implementation BroadcastCalendar
-
-@synthesize username;
-@synthesize broadcastDates;
-
-+ (void)initialize {
- [self setDelegate:self];
- [self setBaseURL:[NSURL URLWithString:@"http://localhost:3000"]];
-}
-
-- (void)initWithDates:(NSArray *)broadcastDates {
- if(self = [super init]) {
- self.broadcastDates = broadcastDates;
- }
- return self;
-}
-
-
-#pragma mark - HRRequestOperation Delegates
-+ (void)restConnection:(NSURLConnection *)connection didFailWithError:(NSError *)error object:(id)object {
- // Handle connection errors. Failures to connect to the server, etc.
-}
-
-+ (void)restConnection:(NSURLConnection *)connection didReceiveError:(NSError *)error response:(NSHTTPURLResponse *)response object:(id)object {
- // Handle invalid responses, 404, 500, etc.
-}
-
-+ (void)restConnection:(NSURLConnection *)connection didReceiveParseError:(NSError *)error responseBody:(NSString *)string {
- NSLog(@"Parse error");
- // Request was successful, but couldn't parse the data returned by the server.
-}
-
-// Given I've passed the controller as the <tt>object</tt> here, I can call any method I want to on it
-// giving it a collection of models I've initialized.
-+ (void)restConnection:(NSURLConnection *)connection didReturnResource:(id)resource object:(id)object {
- NSMutableArray *dates = [[[NSMutableArray alloc] init] autorelease];
- NSLog(@"over here!");
- for(id item in resource) {
- NSLog([item description]);
- //[dates addItem:[[Broadcast alloc] initWithDictionary:item]];
- }
-
- //[object performSelector:@selector(tweetsLoaded:) withObject:tweets];
-}
-
-+ (id)getCalendar {
- return [self getPath:@"/users/calendar.json?name=matsimitsu" withOptions:nil object:nil];
-}
-
-@end
-
View
@@ -7,16 +7,20 @@
//
#import <Foundation/Foundation.h>
+#include <HTTPRiot/HTTPRiot.h>
-@interface BroadcastDate : NSObject {
+@interface BroadcastDate : HRRestModel {
NSDate *date;
NSArray *episodes;
+ NSDictionary *dict;
}
@property (retain) NSDate *date;
@property (retain) NSArray *episodes;
+@property (retain) NSDictionary *dict;
- (id)initWithDate:(NSDate *)date episodes:(NSArray *)episodes;
+- (id)initWithDictionary:(NSDictionary *)dict;
@end
View
@@ -14,6 +14,11 @@ @implementation BroadcastDate
@synthesize date;
@synthesize episodes;
++ (void)initialize {
+ [self setDelegate:self];
+ [self setBaseURL:[NSURL URLWithString:@"http://localhost:3000"]];
+}
+
- (id)initWithDate:(NSDate *)date episodes:(NSArray *)episodes
{
if (self = [super init]) {
@@ -25,4 +30,34 @@ - (id)initWithDate:(NSDate *)date episodes:(NSArray *)episodes
return nil;
}
+- (id)initWithDictionary:(NSDictionary *)dict {
+ if(self = [super init]) {
+
+ NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
+ dateFormatter.dateFormat = @"yyyy-mm-dd";
+
+ self.date = [dateFormatter dateFromString:[dict valueForKeyPath:@"date"]];
+ self.episodes = [dict valueForKey:@"episodes"];
+ }
+
+ return self;
+}
+
+
++ (void)restConnection:(NSURLConnection *)connection didReturnResource:(id)resource object:(id)object {
+ NSMutableArray *dates = [[[NSMutableArray alloc] init] autorelease];
+
+ for(id item in resource) {
+ [dates addObject:[[BroadcastDate alloc] initWithDictionary:item]];
+ }
+
+ // Let the tableview know we have new dates
+ [object performSelector:@selector(datesLoaded:) withObject:dates];
+}
+
++ (id)getDates:(id)object {
+ return [self getPath:@"/users/calendar.json?name=matsimitsu" withOptions:nil object:object];
+}
+
+
@end
@@ -8,7 +8,6 @@
#import "RootViewController.h"
#import "BroadcastDate.h"
-#import "BroadcastCalendar.h"
@implementation RootViewController
@@ -18,17 +17,15 @@ @implementation RootViewController
#pragma mark -
#pragma mark View lifecycle
+- (void)datesLoaded:(id *)dates {
+ self.broadcastDates = dates;
+ [self.tableView reloadData];
+}
- (void)viewDidLoad {
[super viewDidLoad];
- NSArray *calendar = [BroadcastCalendar getCalendar];
- NSLog([calendar description]);
- // self.dates = [NSArray arrayWithObjects:[NSArray arrayWithObjects:@"Fringe", nil], [NSArray arrayWithObjects:@"Doctor Who", nil], nil];
- BroadcastDate *date1 = [[BroadcastDate alloc] initWithDate:[NSDate distantPast] episodes:[NSArray arrayWithObjects:@"Doctor Who", nil]];
- BroadcastDate *date2 = [[BroadcastDate alloc] initWithDate:[NSDate distantFuture] episodes:[NSArray arrayWithObjects:@"Fringe", nil]];
-
- self.broadcastDates = [NSArray arrayWithObjects: date1, date2, nil];
+ [BroadcastDate getDates:self];
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
@@ -82,7 +79,6 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
- NSLog(@"hiero");
BroadcastDate *broadcastDate = [broadcastDates objectAtIndex:section];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
@@ -104,7 +100,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
// Configure the cell.
BroadcastDate *date = [broadcastDates objectAtIndex:indexPath.section];
- cell.textLabel.text = [date.episodes objectAtIndex:indexPath.row];
+ NSDictionary *episode = [date.episodes objectAtIndex:indexPath.row];
+ cell.textLabel.text = [episode valueForKeyPath:@"show.title"];
return cell;
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -2,4 +2,3 @@
/Users/robertbeekman/Sites/apps/iTrakt/build/iTrakt.build/Debug-iphonesimulator/iTrakt.build/Objects-normal/i386/RootViewController.o
/Users/robertbeekman/Sites/apps/iTrakt/build/iTrakt.build/Debug-iphonesimulator/iTrakt.build/Objects-normal/i386/BroadcastDate.o
/Users/robertbeekman/Sites/apps/iTrakt/build/iTrakt.build/Debug-iphonesimulator/iTrakt.build/Objects-normal/i386/main.o
-/Users/robertbeekman/Sites/apps/iTrakt/build/iTrakt.build/Debug-iphonesimulator/iTrakt.build/Objects-normal/i386/BroadcastCalendar.o
Oops, something went wrong.

0 comments on commit 95105d9

Please sign in to comment.