Created
February 22, 2012 21:08
-
-
Save almost/1887280 to your computer and use it in GitHub Desktop.
Here you go josh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewTestViewController.m | |
// ViewTest | |
// | |
// Created by Joshua Theed on 10/01/2012. | |
// Copyright 2012 __MyCompanyName__. All rights reserved. | |
// | |
#import "ViewRecordsViewController.h" | |
#import "CustomTableViewCell.h" | |
#import "GlucoseCell.h" | |
#import "KetonesCell.h" | |
#import "MedicationCell.h" | |
#import "ExerciseCell.h" | |
#import "FoodCell.h" | |
#import "NotesCell.h" | |
#import "EditGlucoseRecordViewController.h" | |
#import "EditKetoneRecordViewController.h" | |
#import "EditMedicationRecordViewController.h" | |
#import "EditExerciseRecordViewController.h" | |
#import "EditFoodRecordViewController.h" | |
#import "EditNotesRecordViewController.h" | |
#import "DataManager.h" | |
@implementation ViewRecordsViewController | |
@synthesize recordData; | |
- (void)awakeFromNib{ | |
//// TOODO HERE: Instansiate a DataManager and store it in a property of this classj | |
} | |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ | |
//// TOODO HERE: Lookup the day given by indexPath.section and the item given by indexPath.row | |
//// Figure out what sort of cell it is from the data you just looked up. Create a cell and return it. | |
static NSString *GCellIdentifier = @"GlucoseCell"; | |
static NSString *KCellIdentifier = @"KetonesCell"; | |
static NSString *MCellIdentifier = @"MedicationCell"; | |
static NSString *ECellIdentifier = @"ExerciseCell"; | |
static NSString *FCellIdentifier = @"FoodCell"; | |
static NSString *NCellIdentifier = @"NotesCell"; | |
//Glucose Cell | |
if (indexPath.row == 0){ | |
GlucoseCell *cell = (GlucoseCell *)[tableView dequeueReusableCellWithIdentifier:GCellIdentifier]; | |
if (cell == nil) { | |
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"GlucoseCell" owner:nil options:nil]; | |
for (id currentObject in topLevelObjects) { | |
cell = (GlucoseCell *)currentObject; | |
break; | |
} | |
} | |
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; | |
return cell; | |
} | |
//Ketones Cell | |
else if (indexPath.row == 1){ | |
KetonesCell *cell = (KetonesCell *)[tableView dequeueReusableCellWithIdentifier:KCellIdentifier]; | |
if (cell == nil) { | |
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"KetonesCell" owner:nil options:nil]; | |
for (id currentObject in topLevelObjects) { | |
cell = (KetonesCell *)currentObject; | |
break; | |
} | |
} | |
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; | |
return cell; | |
} | |
//Medication Cell | |
else if (indexPath.row == 2){ | |
MedicationCell *cell = (MedicationCell *)[tableView dequeueReusableCellWithIdentifier:MCellIdentifier]; | |
if (cell == nil) { | |
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"MedicationCell" owner:nil options:nil]; | |
for (id currentObject in topLevelObjects) { | |
cell = (MedicationCell *)currentObject; | |
break; | |
} | |
} | |
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; | |
return cell; | |
} | |
//Exercise Cell | |
else if (indexPath.row == 3){ | |
ExerciseCell *cell = (ExerciseCell *)[tableView dequeueReusableCellWithIdentifier:ECellIdentifier]; | |
if (cell == nil) { | |
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"ExerciseCell" owner:nil options:nil]; | |
for (id currentObject in topLevelObjects) { | |
cell = (ExerciseCell *)currentObject; | |
break; | |
} | |
} | |
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; | |
return cell; | |
} | |
//Food Cell | |
else if (indexPath.row == 4){ | |
FoodCell *cell = (FoodCell *)[tableView dequeueReusableCellWithIdentifier:FCellIdentifier]; | |
if (cell == nil) { | |
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"FoodCell" owner:nil options:nil]; | |
for (id currentObject in topLevelObjects) { | |
cell = (FoodCell *)currentObject; | |
break; | |
} | |
} | |
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; | |
return cell; | |
} | |
//Notes Cell | |
else if (indexPath.row == 5){ | |
NotesCell *cell = (NotesCell *)[tableView dequeueReusableCellWithIdentifier:NCellIdentifier]; | |
if (cell == nil) { | |
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"NotesCell" owner:nil options:nil]; | |
for (id currentObject in topLevelObjects) { | |
cell = (NotesCell *)currentObject; | |
break; | |
} | |
} | |
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; | |
return cell; | |
} | |
static NSString *CellIdentifier = @"Cell"; | |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; | |
if (cell == nil) { | |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; | |
} | |
// Configure the cell... | |
return cell; | |
//Non-void need to return a cell with an error in it - fix later | |
} | |
//Method responds to actions on specific customCell within a section header | |
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ | |
if ([indexPath indexAtPosition:1] == 4) { | |
//Creates a view controller | |
EditGlucoseRecordViewController *vcEditGlucoseRecord = [[EditGlucoseRecordViewController alloc] initWithNibName:@"EditGlucoseRecordViewController" bundle:nil]; | |
//pushes view onto the stack | |
[self.navigationController pushViewController:vcEditGlucoseRecord animated:YES]; | |
[vcEditGlucoseRecord release]; | |
NSLog(@"Row at %i selected",[indexPath indexAtPosition:1]); | |
} | |
else if ([indexPath indexAtPosition:1] == 5) { | |
//Creates a view controller | |
EditKetoneRecordViewController *vcEditKetoneRecord = [[EditKetoneRecordViewController alloc] initWithNibName:@"EditKetoneRecordViewController" bundle:nil]; | |
//pushes view onto the stack | |
[self.navigationController pushViewController:vcEditKetoneRecord animated:YES]; | |
[vcEditKetoneRecord release]; | |
NSLog(@"Row at %i selected",[indexPath indexAtPosition:1]); | |
} | |
else if ([indexPath indexAtPosition:1] == 6) { | |
//Creates a view controller | |
EditMedicationRecordViewController *vcEditMedicationRecord = [[EditMedicationRecordViewController alloc] initWithNibName:@"EditMedicationRecordViewController" bundle:nil]; | |
//pushes view onto the stack | |
[self.navigationController pushViewController:vcEditMedicationRecord animated:YES]; | |
[vcEditMedicationRecord release]; | |
NSLog(@"Row at %i selected",[indexPath indexAtPosition:1]); | |
} | |
else if ([indexPath indexAtPosition:1] == 7) { | |
//Creates a view controller | |
EditExerciseRecordViewController *vcEditExerciseRecord = [[EditExerciseRecordViewController alloc] initWithNibName:@"EditExerciseRecordViewController" bundle:nil]; | |
//pushes view onto the stack | |
[self.navigationController pushViewController:vcEditExerciseRecord animated:YES]; | |
[vcEditExerciseRecord release]; | |
NSLog(@"Row at %i selected",[indexPath indexAtPosition:1]); | |
} | |
else if ([indexPath indexAtPosition:1] == 8) { | |
//Creates a view controller | |
EditFoodRecordViewController *vcEditFoodRecord = [[EditFoodRecordViewController alloc] initWithNibName:@"EditFoodRecordViewController" bundle:nil]; | |
//pushes view onto the stack | |
[self.navigationController pushViewController:vcEditFoodRecord animated:YES]; | |
[vcEditFoodRecord release]; | |
NSLog(@"Row at %i selected",[indexPath indexAtPosition:1]); | |
} | |
else if ([indexPath indexAtPosition:1] == 9) { | |
//Creates a view controller | |
EditNotesRecordViewController *vcEditNotesRecord = [[EditNotesRecordViewController alloc] initWithNibName:@"EditNotesRecordViewController" bundle:nil]; | |
//pushes view onto the stack | |
[self.navigationController pushViewController:vcEditNotesRecord animated:YES]; | |
[vcEditNotesRecord release]; | |
NSLog(@"Row at %i selected",[indexPath indexAtPosition:1]); | |
} | |
//Removes cell highlight instantly | |
[tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
/* | |
//Renames Back Button to "Back" instead of "Records" | |
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil]; | |
self.navigationItem.backBarButtonItem = backButton; | |
[backButton release]; | |
*/ | |
} | |
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ | |
//Number of Cells to display in first section | |
if(section == 0){ | |
return 6; | |
} | |
//Number of Cells to display in second section | |
else if(section == 1){ | |
return 3; | |
} | |
//Number of Cells to display in third section | |
else if(section == 2){ | |
return 3; | |
} | |
//Number of Cells to display in fourth section | |
else{ | |
return 3; | |
} | |
} | |
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ | |
return 3; | |
} | |
//Section header | |
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ | |
NSString *header = @"Section Header"; | |
return header; | |
} | |
/* | |
// The designated initializer. Override to perform setup that is required before the view is loaded. | |
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { | |
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; | |
if (self) { | |
// Custom initialization | |
} | |
return self; | |
} | |
*/ | |
/* | |
// Implement loadView to create a view hierarchy programmatically, without using a nib. | |
- (void)loadView { | |
} | |
*/ | |
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
UIBarButtonItem *add=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:nil action:nil]; | |
self.navigationItem.rightBarButtonItem = add; | |
[add release]; | |
UIBarButtonItem *edit=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:nil action:nil]; | |
self.navigationItem.leftBarButtonItem = edit; | |
[edit release]; | |
//Sets Navigation toolbar at bottom of the page to visible | |
self.navigationController.toolbarHidden = NO; | |
} | |
/* | |
// Override to allow orientations other than the default portrait orientation. | |
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { | |
// Return YES for supported orientations | |
return (interfaceOrientation == UIInterfaceOrientationPortrait); | |
} | |
*/ | |
- (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. | |
} | |
- (void)viewDidUnload { | |
// Release any retained subviews of the main view. | |
// e.g. self.myOutlet = nil; | |
} | |
- (void)dealloc { | |
[super dealloc]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment