Skip to content

Commit

Permalink
Implemented the weather tab. Added a data model for the courses and l…
Browse files Browse the repository at this point in the history
…ocation objects. Implemented the state selection and course selection view controllers for the course directory tab. Added a database initialization class to init a default sqlite file. added tee and green pin images for the map view. Added the TBXML library for parsing the yahoo weather information.
  • Loading branch information
Teacher committed May 19, 2011
1 parent f7c182f commit 36b3147
Show file tree
Hide file tree
Showing 28 changed files with 2,970 additions and 132 deletions.
81 changes: 75 additions & 6 deletions ECaddy.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions ECaddy/CourseSelectViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// CourseSelectViewController.h
// ECaddy
//
// Created by Teacher on 5/18/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>


@interface CourseSelectViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>{

NSMutableArray* courseNames;
NSMutableArray* courseLocs;
NSString* selectedState;
NSManagedObjectContext* manObjCon;
}

@property (nonatomic, retain) NSMutableArray* courseNames;
@property (nonatomic, retain) NSMutableArray* courseLocs;
@property (nonatomic, retain) NSString* selectedState;
@property (nonatomic, retain) NSManagedObjectContext* manObjCon;

- (void) fillNamesAndLocs;

@end
155 changes: 155 additions & 0 deletions ECaddy/CourseSelectViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
//
// CourseSelectViewController.m
// ECaddy
//
// Created by RKing on 5/18/11.
// Copyright 2011 RPKing. All rights reserved.
//

#import "CourseSelectViewController.h"

@implementation CourseSelectViewController

@synthesize courseNames, courseLocs;
@synthesize selectedState;
@synthesize manObjCon;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}

- (void)dealloc
{
[courseNames release];
[courseLocs release];
[super dealloc];

}

- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.

// Set the title in the navigation bar
[self.navigationItem setTitle:@"Course Select"];

self.courseNames = [[NSMutableArray alloc] init];
self.courseLocs = [[NSMutableArray alloc] init];

// Fill the course names and locations
[self fillNamesAndLocs];
}

- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
self.courseLocs = nil;
self.courseNames = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void) fillNamesAndLocs
{
if(!self.selectedState){
// Do something here to handle the case where an invalid state may
// have been selected (not sure why that would happen
}

NSFetchRequest* fetchrequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Course" inManagedObjectContext:self.manObjCon];
[fetchrequest setEntity:entity];

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"state == %@", self.selectedState];
[fetchrequest setPredicate:predicate];

NSSortDescriptor* sortDescript = [[NSSortDescriptor alloc] initWithKey:@"coursename" ascending:YES];
NSArray* sdArr = [[NSArray alloc] initWithObjects: sortDescript, nil];
[fetchrequest setSortDescriptors: sdArr];

NSError *error = nil;
NSArray *array = [self.manObjCon executeFetchRequest:fetchrequest error:&error];
if (array != nil) {
NSString* nameStr = nil;
NSString* locStr = nil;

for(NSManagedObject* manObj in array){

nameStr = [manObj valueForKey: @"coursename"];
locStr = [manObj valueForKey: @"address"];

[self.courseNames addObject: nameStr];
[self.courseLocs addObject: locStr];
}

}
else {
// Deal with error.
NSLog(@"Error fetching lots");
}

[sortDescript release];
[sdArr release];
[fetchrequest release];

}

#pragma mark UITableViewDataSource Protocol Methods

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

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath: indexPath animated:NO];
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"CourseTableCell";

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

// Set up the cell...
UILabel* lbl = [cell textLabel];
[lbl setText: [self.courseNames objectAtIndex:indexPath.row]];

UILabel* lbl2 = [cell detailTextLabel];
[lbl2 setText: [self.courseLocs objectAtIndex:indexPath.row]];

[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];

return cell;
}


@end
18 changes: 17 additions & 1 deletion ECaddy/DirectoryViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,26 @@
//

#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>


@interface DirectoryViewController : UIViewController <UITableViewDataSource, UITableViewDelegate> {


NSSet* stateSet;
NSSet* countrySet;
NSDictionary* abbrsDict;
NSDictionary* stateArrDict;
NSManagedObjectContext* manObjCon;
UINavigationController *navController;
}
@property (nonatomic, retain) IBOutlet UINavigationController *navController;

@property (nonatomic, retain) NSSet* stateSet;
@property (nonatomic, retain) NSSet* countrySet;
@property (nonatomic, retain) NSDictionary* abbrsDict;
@property (nonatomic, retain) NSDictionary* stateArrDict;
@property (nonatomic, retain) NSManagedObjectContext* manObjCon;

- (void) fillStatesCountries;

@end
124 changes: 114 additions & 10 deletions ECaddy/DirectoryViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,30 @@
//

#import "DirectoryViewController.h"

#import "CourseSelectViewController.h"

@implementation DirectoryViewController
@synthesize navController;

@synthesize stateSet, countrySet, abbrsDict, stateArrDict;
@synthesize manObjCon;


/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];

// Initialize abbreviation dictionary
NSString* stateAbbrsPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"stateabbrs.txt"];
self.abbrsDict = [[NSDictionary alloc] initWithContentsOfFile: stateAbbrsPath];

// Fill state and country sets
[self fillStatesCountries];

[self.navigationItem setTitle: @"State Select"];
}
*/


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
Expand Down Expand Up @@ -46,23 +59,108 @@ - (void)didReceiveMemoryWarning

- (void)viewDidUnload
{
[self setNavController:nil];
[super viewDidUnload];

// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
self.stateSet = nil;
self.countrySet = nil;
self.abbrsDict = nil;
self.stateArrDict = nil;
}


- (void)dealloc
{
[stateSet release];
[countrySet release];
[abbrsDict release];
[stateArrDict release];
[navController release];
[super dealloc];
}

- (void) fillStatesCountries
{
NSFetchRequest* fetchrequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Location" inManagedObjectContext:self.manObjCon];
[fetchrequest setEntity:entity];

NSError *error = nil;
NSArray *array = [self.manObjCon executeFetchRequest:fetchrequest error:&error];
if (array != nil) {
NSString* state = nil;
NSString* country = nil;
NSMutableSet* sSet = [[NSMutableSet alloc] init];
NSMutableSet* cSet = [[NSMutableSet alloc] init];
NSMutableDictionary* saDict = [[NSMutableDictionary alloc] init];
NSMutableArray* tmpArr = nil;

for(NSManagedObject* manObj in array){
country = [manObj valueForKey: @"country"];
state = [manObj valueForKey: @"state"];

if((![sSet member: state]) && [cSet member: country]){
tmpArr = (NSMutableArray*) [saDict valueForKey: country];
[tmpArr addObject:state];
[saDict setValue: tmpArr forKey: country];
}
else if(![cSet member: country]) {
tmpArr = [[NSMutableArray alloc] initWithObjects: state, nil];
[saDict setObject: tmpArr forKey: country];
[tmpArr release]; tmpArr = nil;
}

[cSet addObject: country];
[sSet addObject: state];
}

self.stateSet = [[NSSet alloc] initWithSet: sSet];
self.countrySet = [[NSSet alloc] initWithSet: cSet];
self.stateArrDict = [[NSDictionary alloc] initWithDictionary: saDict];

[sSet release]; sSet = nil;
[cSet release]; cSet = nil;
[saDict release]; saDict = nil;
}
else {
// Deal with error.
NSLog(@"Error fetching lots");
}

[fetchrequest release];
[manObjCon reset];

}

#pragma mark UITableViewDataSource Protocol Methods

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
NSString* countryStr = [[countrySet allObjects] objectAtIndex: section];
return [[stateArrDict objectForKey: countryStr] count];
}

- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
return [self.countrySet count];
}

- (NSString*) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
NSString* countryAbbr = [[countrySet allObjects] objectAtIndex: section];
return [abbrsDict valueForKey: countryAbbr];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath: indexPath animated:NO];
CourseSelectViewController* csvc = [[CourseSelectViewController alloc] initWithNibName:@"CourseSelectView" bundle:nil];
csvc.manObjCon = self.manObjCon;
NSString* countryStr = [[countrySet allObjects] objectAtIndex: indexPath.section];
csvc.selectedState = [[stateArrDict valueForKey: countryStr] objectAtIndex: indexPath.row];

[self.navController pushViewController:csvc animated:YES];
}

// Customize the appearance of table view cells.
Expand All @@ -73,15 +171,21 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
//cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
}

NSString* countryStr = [[countrySet allObjects] objectAtIndex: indexPath.section];
NSString* stateStr = [[stateArrDict valueForKey: countryStr] objectAtIndex: indexPath.row];

// Set up the cell...
NSString *cellValue = @"Active Course";
UILabel* lbl = [cell textLabel];
[lbl setText: cellValue];
UILabel* lbl2 = [cell detailTextLabel];
[lbl2 setText: @"Country Fareways"];
//[lbl setText: [self.courseNames objectAtIndex:indexPath.row]];
[lbl setText: [abbrsDict valueForKey: stateStr]];
//UILabel* lbl2 = [cell detailTextLabel];
//[lbl2 setText: [self.courseLocs objectAtIndex:indexPath.row]];
//[lbl2 setText: @"Row2"];

[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];

return cell;
}
Expand Down
Binary file added ECaddy/ECaddy.sqlite
Binary file not shown.
Loading

0 comments on commit 36b3147

Please sign in to comment.