Filename : TableViewStory/ChangePictureCell.m // // ChangePictureCell.m // TableViewStory // // Created by Oliver Jarrett on 22/02/2013. // Copyright (c) 2013 Oliver Jarrett. All rights reserved. // #import "ChangePictureCell.h" @implementation ChangePictureCell - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { // Initialization code } return self; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } @end Filename : TableViewStory/ChangePictureTable.m // // ChangePictureTable.m // TableViewStory // // Created by Oliver Jarrett on 22/02/2013. // Copyright (c) 2013 Oliver Jarrett. All rights reserved. // #import "ChangePictureTable.h" #import "ChangePictureCell.h" @interface ChangePictureTable () @property (nonatomic) NSArray *coverFilePath; @property (nonatomic) NSArray *coverStickers; @property (nonatomic) NSArray *coverComplete; @property (nonatomic, strong) NSString *cover; @property (nonatomic, strong) NSString *stickerCount; @property (nonatomic, strong) NSString *completeCount; @end @implementation ChangePictureTable - (id)initWithStyle:(UITableViewStyle)style { self = [super initWithStyle:style]; if (self) { // Custom initialization self.name = [[NSString alloc]init]; } return self; } -(IBAction)changeObject:(id)sender { [self viewWillAppear:nil]; [self.tableView reloadData]; } -(void)viewWillAppear:(BOOL)animated { self.coverFilePath = [[NSArray alloc]initWithObjects:@"Blank",@"cool.jpg",@"girly.jpg",@"normal.jpg", nil]; self.coverStickers = [[NSArray alloc]initWithObjects:@"0",@"1",@"0",@"0", nil]; self.coverComplete = [[NSArray alloc]initWithObjects:@"0",@"0",@"1",@"2", nil]; [self getPreferences]; } -(NSString*) filePath { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); return [[paths objectAtIndex:0] stringByAppendingPathComponent:@"bp.sql"]; } -(void)openDB { //open Child Table if (sqlite3_open([[self filePath] UTF8String], &Childdb)!= SQLITE_OK) { sqlite3_close(Childdb); NSAssert(0, @"Database failed to open"); } else { NSLog(@"Database Opened"); } } -(void)getPreferences { [self openDB]; NSLog(@"%@",self.name); NSString *sql = [NSString stringWithFormat:@"SELECT Cover, Current_Stickers, Completed FROM Children WHERE Name = '%@'", self.name]; sqlite3_stmt *statement; if (sqlite3_prepare_v2(Childdb, [sql UTF8String], -1, &statement, nil)==SQLITE_OK) { while (sqlite3_step(statement)==SQLITE_ROW) { char *field1 = (char *) sqlite3_column_text(statement, 0); self.cover =[[NSString alloc]initWithUTF8String:field1]; char *field3 = (char *) sqlite3_column_text(statement, 1); self.stickerCount = [[NSString alloc]initWithUTF8String:field3]; char *field4 = (char *) sqlite3_column_text(statement, 2); self.completeCount = [[NSString alloc]initWithUTF8String:field4]; } } } - (void)viewDidLoad { [super viewDidLoad]; // Uncomment the following line to preserve selection between presentations. // self.clearsSelectionOnViewWillAppear = NO; // Uncomment the following line to display an Edit button in the navigation bar for this view controller. // self.navigationItem.rightBarButtonItem = self.editButtonItem; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { #warning Potentially incomplete method implementation. // Return the number of sections. return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { #warning Incomplete method implementation. // Return the number of rows in the section. return [self.coverFilePath count]; } -(BOOL)checkAchieved:(int)i { // if the person has the matching complete count and sticker count and over then its unlocked if ([self.completeCount integerValue] == [[self.coverComplete objectAtIndex:i]integerValue] & [self.stickerCount integerValue] >= [[self.coverStickers objectAtIndex:i]integerValue]) { return TRUE; // if the person has more complete than the required complete count then its unlocked regardless of sticker count. } else if ([self.completeCount integerValue] > [[self.coverComplete objectAtIndex:i]integerValue]) { return TRUE; } else { // doesn't qualify for the unlock. return FALSE; } } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"achievementCell"; // ChangePictureCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; ChangePictureCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[ChangePictureCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } // Configure the cell... NSBundle* bundle = [NSBundle mainBundle]; if ([[self.coverFilePath objectAtIndex:indexPath.row] isEqualToString:@"Blank"]) { cell.cover.backgroundColor = [UIColor scrollViewTexturedBackgroundColor]; cell.cover.image = nil; } else { cell.cover.image = [UIImage imageWithContentsOfFile:[bundle pathForResource:[self.coverFilePath objectAtIndex:indexPath.row] ofType:nil]]; cell.complete.text = [self.coverComplete objectAtIndex:indexPath.row]; cell.stickers.text = [self.coverStickers objectAtIndex:indexPath.row]; } // cell.complete.text = [self.coverComplete objectAtIndex:indexPath.row]; // cell.stickers.text = [self.coverStickers objectAtIndex:indexPath.row]; if ([[self.coverFilePath objectAtIndex:indexPath.row ] isEqualToString:self.cover]) { cell.tick.hidden = FALSE; } else { cell.tick.hidden = TRUE; } NSLog(@"This is the persons complete count: %@",self.completeCount); NSLog(@"This is the persons sticker count: %@",self.stickerCount); NSLog(@"This is the required complete count: %@", [self.coverComplete objectAtIndex:indexPath.row]); NSLog(@"This is the required sticker count: %@", [self.coverStickers objectAtIndex:indexPath.row]); // if its not unlocked then disable the cell from being selected. if (![self checkAchieved:indexPath.row]) { [cell setUserInteractionEnabled:NO]; } return cell; } /* // Override to support conditional editing of the table view. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the specified item to be editable. return YES; } */ /* // Override to support editing the table view. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { // Delete the row from the data source [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; } else if (editingStyle == UITableViewCellEditingStyleInsert) { // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view } } */ /* // Override to support rearranging the table view. - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { } */ /* // Override to support conditional rearranging of the table view. - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the item to be re-orderable. return YES; } */ -(void)updatetable:(NSString*)sql { char *err; if (sqlite3_exec(Childdb, [sql UTF8String], NULL, NULL, &err)!=SQLITE_OK) { sqlite3_close(Childdb); NSAssert(0, @"Could not update Table"); } else { NSLog(@"Table updated"); } } -(void)updatePreferences { NSString *sql = [NSString stringWithFormat:@"UPDATE Children SET 'Cover' = '%@' WHERE Name = '%@'", self.cover,self.name]; [self updatetable:sql]; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { self.cover = [self.coverFilePath objectAtIndex:indexPath.row]; [self updatePreferences]; [tableView reloadData]; // 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]; */ } @end Filename : TableViewStory/ChildrenDetailControl.m // // ChildrenDetailControl.m // TableViewStory // // Created by Oliver Jarrett on 25/02/2013. // Copyright (c) 2013 Oliver Jarrett. All rights reserved. // #import "ChildrenDetailControl.h" @implementation ChildrenDetailControl -(void)setCompletecount:(UILabel *)completecount { _completecount = completecount; [self setNeedsDisplay]; } -(void)setStickercount:(UILabel *)stickercount { _stickercount = stickercount; [self setNeedsDisplay]; } -(void)setLeaderUp:(BOOL *)leaderUp { _leaderUp = leaderUp; if (leaderUp) { self.redeem.hidden = TRUE; self.picture.hidden = TRUE; self.cover.hidden = TRUE; self.scan.hidden = TRUE; self.up.hidden = FALSE; self.down.hidden = FALSE; self.nexttarget.hidden = FALSE; self.behindyou.hidden = FALSE; self.you.hidden = FALSE; self.stickercount.hidden = FALSE; self.completecount.hidden = FALSE; self.completelabel.hidden = FALSE; self.stickerlabel.hidden = FALSE; } else { self.redeem.hidden = FALSE; self.picture.hidden = FALSE; self.cover.hidden = FALSE; self.scan.hidden = FALSE; self.up.hidden = TRUE; self.down.hidden = TRUE; self.nexttarget.hidden = TRUE; self.behindyou.hidden = TRUE; self.you.hidden = TRUE; self.stickercount.hidden = TRUE; self.completecount.hidden = TRUE; self.completelabel.hidden = TRUE; self.stickerlabel.hidden = TRUE; } [self setNeedsDisplay]; } -(void)setup { } -(void)awakeFromNib { [self setup]; } -(id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; [self setup]; return self; } - (void)drawRect:(CGRect)rect { // Drawing code UIBezierPath *roundedRect = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:0]; [roundedRect addClip]; if (self.leaderUp) { [[UIColor whiteColor]setFill]; } else { [[UIColor darkGrayColor]setFill]; /* UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button addTarget:self action:@selector(awakeFromNib) forControlEvents:UIControlEventTouchDown]; [button setTitle:@"Show View" forState:UIControlStateNormal]; button.frame = CGRectMake(20, 10, 80, 80); [self addSubview:button];*/ } UIRectFill(self.bounds); [[UIColor blackColor]setStroke]; [roundedRect stroke]; } @end Filename : TableViewStory/ChildrenDetailViewController.m // // ChildrenDetailViewController.m // TableViewStory // // Created by Oliver Jarrett on 28/10/2012. // Copyright (c) 2012 Oliver Jarrett. All rights reserved. // #import "ChildrenDetailViewController.h" #import "QRReader.h" #import #import "ChangePictureTable.h" @interface ChildrenDetailViewController () @end @implementation ChildrenDetailViewController @synthesize childname; @synthesize imageview; @synthesize name, redeem, IsItComplete,completecount,stickercount, randomstick; @synthesize tickets,stickerarray,touchDownStickers,random,stick; @synthesize flash1,flash2,flash3,flash4,flash5,flash6,flash7,flash8,flash9,flash10,flash11,flash12,flash13,flash14,flash15,flash16; @synthesize button1,button2,button3,button4,button5,button6,button7,button8,button9,button10,button11,button12,button13,button14,button15,button16; @synthesize animation, totaltickets, displaypicture, scanticket, displaypic, changecov; @synthesize nexttarget,behindyou,Hub; -(IBAction)switchViews:(id)sender { QRReader *model = [[QRReader alloc]initWithNibName:nil bundle:nil]; model.modalPresentationStyle = UIModalPresentationFormSheet; [model setDelegate:self]; model.userName = self.title;//passes the name of the user to the QRReader Controller, so it knows whos using it. [self presentModalViewController:model animated:YES]; } - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([[segue identifier] isEqualToString:@"ChangeTheme"]) { ChangePictureTable *PictureTable = [segue destinationViewController]; PictureTable.name = name; } } - (void)setTicketLabel:(BOOL *)sender:(NSString*)message:(int)value { if (sender) { self.tickets.text = [[NSNumber numberWithInt:[self.tickets.text integerValue] + value] stringValue]; totaltickets = [[NSNumber numberWithInt:[totaltickets integerValue] + value]stringValue]; //flash the message if (message) {// if theres a message then flash it. [self.message setTitle:message forState:UIControlStateNormal]; [UIView animateWithDuration:2 animations:^{ self.message.alpha = 0.1; }completion:^(BOOL finished) { [UIView animateWithDuration:2 animations:^{ self.message.alpha = 1; }]; }]; } [self UpdatecurrentTickets]; [self updateLastTicketDate]; } } - (void)viewWillAppear:(BOOL)animated{ //when the view is returned or loaded it updates these variables. [self tableSetUp]; [self hiddenCircles]; } - (BOOL)complete { if ([stickerarray containsObject:@"0"]) { return FALSE; } else { return TRUE ; } } -(IBAction)touchDownSticker: (id)sender: (UIButton*) stickers;{ UIButton *resultButton = (UIButton *)sender; buttonpress = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"button_press" ofType:@"mp3"]];//set the play sound to the button sound. button_press = [[AVAudioPlayer alloc] initWithContentsOfURL:buttonpress error:nil]; button_press.volume = 0.1; [button_press play]; NSLog(@" The button's title is %@." ,resultButton.currentTitle); for (int i = 0; i < 2; i++) { if ([[touchDownStickers objectAtIndex:i]isEqualToString:@"0"]) { [touchDownStickers removeObjectAtIndex:i]; [touchDownStickers insertObject:resultButton.currentTitle atIndex:i]; NSLog(@"%@",touchDownStickers); break; } } } -(IBAction)touchUpSticker: (id) sender: (UIButton*) stickers1;{ UIButton *resultButton = (UIButton *)sender; for (int i = 0; i < 2; i++) { if ([[touchDownStickers objectAtIndex:i]isEqualToString:resultButton.currentTitle]) { [touchDownStickers removeObjectAtIndex:i]; [touchDownStickers insertObject:@"0" atIndex:i]; break; } } } -(void)updateShowMessage:(int)Show { NSString *sql = [NSString stringWithFormat:@"UPDATE Children SET Showmessage = %d WHERE Name = '%@'", Show,name]; [self updatetable:sql]; } - (IBAction)hideShowMessage:(UIButton*)sender { if (sender.alpha < 0.3) { sender.alpha = 1; [self updateShowMessage:1]; } else { sender.alpha = 0.1 ; [self updateShowMessage:0]; } } -(void)flashbutton:(id)sender { UIButton *img = (UIButton*)sender; img.alpha = 0.8; [UIImageView beginAnimations: @"FadeOut" context: nil]; [UIImageView setAnimationDelegate: self]; [UIImageView setAnimationDuration: 0.6]; [UIImageView setAnimationCurve: UIViewAnimationCurveEaseInOut]; img.alpha = 0.1; [UIImageView commitAnimations]; } -(void)flashobject:(id)sender { [self sound:musicFile]; UIImageView *img = (UIImageView*)sender; img.alpha = 0.8; [UIImageView beginAnimations: @"FadeOut" context: nil]; [UIImageView setAnimationDelegate: self]; [UIImageView setAnimationDuration: 0.6]; [UIImageView setAnimationCurve: UIViewAnimationCurveEaseInOut]; img.alpha = img.alpha - 1; [UIImageView commitAnimations]; } -(void)sound: (id)sender { click = [[AVAudioPlayer alloc] initWithContentsOfURL:sender error:nil]; click.volume = 0.1; [click play]; } -(void)changedp:(id)sender { if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.sourceType = UIImagePickerControllerSourceTypeCamera; picker.delegate = self; [self presentViewController:picker animated:YES completion:nil]; } } -(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; [displaypicture setImage:image]; [self UpdatePicture]; [self dismissViewControllerAnimated:YES completion:nil]; } -(id)returnsticker: (int)o { switch (o) { case 1: return flash1; break; case 2: return flash2; break; case 3: return flash3; break; case 4: return flash4; break; case 5: return flash5; break; case 6: return flash6; break; case 7: return flash7; break; case 8: return flash8; break; case 9: return flash9; break; case 10: return flash10; break; case 11: return flash11; break; case 12: return flash12; break; case 13: return flash13; break; case 14: return flash14; break; case 15: return flash15; break; case 16: return flash16; break; default: break; } } -(void)manageFlash:(id)ii{ int i = [ii intValue]; musicFile = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"button" ofType:@"mp3"]];//set the play sound to the button sound. yay = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"yes" ofType:@"wav"]]; NSLog(@"this is manage flash running %i", i); if (i == 0) {//if first run then initialise currentstick. stick = 0; } if (stick < 16){ stick = stick + 1;//try next button if its available. } else { stick = 1; } if ([touchDownStickers containsObject:[NSString stringWithFormat:@"%d",stick]]) { if (i+1 == random) {//if this is the last one then the selected sticker cannot be unlocked, //unlock the nearest sticker. while (i != 0) {//keep looping until breaked manually. if (stick < 16){ stick = stick + 1;//try next button if its available. } else { stick = 1; } if ([touchDownStickers containsObject:[NSString stringWithFormat:@"%d",stick]]) {//if next number is inside the touchdown array then do nothing, let it reloop and try the next sticker } else { //the next sticker is not in the touchdownarray meaning it shall be unlocked //animate three times. [self performSelector:@selector(flashobject:) withObject:[self returnsticker:stick] afterDelay:.00]; [self performSelector:@selector(flashobject:) withObject:[self returnsticker:stick] afterDelay:.40]; [self performSelector:@selector(flashobject:) withObject:[self returnsticker:stick] afterDelay:.80]; [self performSelector:@selector(flashobject:) withObject:[self returnsticker:stick] afterDelay:1.20]; [self performSelector:@selector(sound:) withObject:yay afterDelay:1.20];//hooray if ([[stickerarray objectAtIndex:stick-1]isEqualToString:@"1"]){ yay = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"no" ofType:@"wav"]]; [self performSelector:@selector(sound:) withObject:yay afterDelay:1.20];//hooray } else { [self performSelector:@selector(flashbutton:) withObject:[self returncircle:stick-1] afterDelay:1.60]; [stickerarray replaceObjectAtIndex:stick-1 withObject:@"1"];//updates the array to indicate that this sticker is unlocked. if ([self complete] == TRUE) {//this is the last sticker of collection [self updatestickercollectioncomplete]; } stickercount++; //[self UpdatecurrentTickets]; self.navigationItem.hidesBackButton = NO; //its clear to start another animation //need to update array. } //pass integer to manage flash queue. self.animation = false; break;//break the loop sticker is unlocked } } } } else if (i+1 == random) { //if this is the last run and it's not inside touchdownstick then animate 3 times to indicate unlocked sticker. [self performSelector:@selector(flashobject:) withObject:[self returnsticker:stick] afterDelay:.00]; [self performSelector:@selector(flashobject:) withObject:[self returnsticker:stick] afterDelay:.40]; [self performSelector:@selector(flashobject:) withObject:[self returnsticker:stick] afterDelay:.80]; [self performSelector:@selector(flashobject:) withObject:[self returnsticker:stick] afterDelay:1.20]; [self performSelector:@selector(sound:) withObject:yay afterDelay:1.20]; self.animation = false;//release animation boolean and allow for another animation to take place. if ([[stickerarray objectAtIndex:stick-1]isEqualToString:@"1"]){ yay = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"no" ofType:@"wav"]]; self.navigationItem.hidesBackButton = NO; [self performSelector:@selector(sound:) withObject:yay afterDelay:1.20]; } else { [self performSelector:@selector(flashbutton:) withObject:[self returncircle:stick-1] afterDelay:1.60]; [stickerarray replaceObjectAtIndex:stick-1 withObject:@"1"]; if ([self complete] == TRUE) {//this is the last sticker of collection [self updatestickercollectioncomplete]; } stickercount++; //[self UpdatecurrentTickets]; self.navigationItem.hidesBackButton = NO; // [theDataObject.stickers replaceObjectAtIndex:childindex withObject:[stickerarray componentsJoinedByString:@" "]]; //clear to start another animation } } else { // else just do the animation because its not inside the array. [self flashobject:[self returnsticker:stick]];//calls returnsticker to return the appropriate sticker then calls flashobject to flash that sticker. } //Now we need to call the updatecurrentTickets method, to update the current state of the sticker collection. [self UpdatecurrentTickets]; } -(void)updateLastTicketDate { NSString *sql = [NSString stringWithFormat:@"UPDATE Children SET 'Last Ticket Scanned' = '%@' WHERE Name = '%@'",[NSDateFormatter localizedStringFromDate:[NSDate date] dateStyle:NSDateFormatterShortStyle timeStyle:NSDateFormatterShortStyle],name]; [self updatetable:sql]; } -(IBAction)UnlockSticker: (UIButton*) stickerbutton; { if (self.animation == false & [self.tickets.text integerValue] > 0 & [self complete] == FALSE ) { // checks whether its clear to start animation and that child has a ticket to use. self.animation = true; //commited to start animation self.tickets.text = [[NSNumber numberWithInt:[self.tickets.text integerValue] - 1] stringValue];//set the current ticket label to decrement. self.navigationItem.hidesBackButton = YES; touchDownStickers = [[NSMutableArray alloc]initWithObjects:@"0",@"0", nil]; float t = 0.0; random = arc4random() %(40) + 25; randomstick = arc4random() %(16); for (int i = randomstick; i < random; i++) { //loops a random number t = t + 0.20; //making the delay longer [self performSelector:@selector(manageFlash:) withObject:([NSNumber numberWithInt:i]) afterDelay:t];//pass integer to manage flash queue. } } else { fail = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"0" ofType:@"mp3"]];//set the play sound to the button sound. failsound = [[AVAudioPlayer alloc] initWithContentsOfURL:fail error:nil]; failsound.volume = 0.1; [failsound play]; } } -(UIButton*)returncircle: (int)n{ switch (n) { case 0: return button1; break; case 1: return button2; break; case 2: return button3; break; case 3: return button4; break; case 4: return button5; break; case 5: return button6; break; case 6: return button7; break; case 7: return button8; break; case 8: return button9; break; case 9: return button10; break; case 10: return button11; break; case 11: return button12; break; case 12: return button13; break; case 13: return button14; break; case 14: return button15; break; case 15: return button16; break; default: break; } } -(void)hiddenCircles { float t = 0.00; for ( int n = 0; n < 16; n++) {//loop around every digit to reveal a sticker if ([[stickerarray objectAtIndex:n]isEqualToString:@"1"]) { t = t + 0.40; [self performSelector:@selector(flashbutton:) withObject:[self returncircle:n] afterDelay:t]; } } } -(void)tableSetUp { [self openDB]; NSString *sql = [NSString stringWithFormat:@"SELECT * FROM Children WHERE Name = '%@' ",name]; //Queries table for the childs name and returns more data. sqlite3_stmt *statement; if (sqlite3_prepare_v2(Childdb, [sql UTF8String], -1, &statement, nil)==SQLITE_OK) { while (sqlite3_step(statement)==SQLITE_ROW) { char *field1 = (char *) sqlite3_column_text(statement, 2); NSString *field1Str = [[NSString alloc]initWithUTF8String:field1]; char *field2 = (char *) sqlite3_column_text(statement, 3); NSString *field2Str = [[NSString alloc]initWithUTF8String:field2]; char *field3 = (char *) sqlite3_column_text(statement, 9); NSString *field3Str = [[NSString alloc]initWithUTF8String:field3]; char *field4 = (char *) sqlite3_column_text(statement, 10); NSString *field4Str = [[NSString alloc]initWithUTF8String:field4]; char *field6 = (char *) sqlite3_column_text(statement, 7); NSString *field6Str = [[NSString alloc]initWithUTF8String:field6]; char *field7 = (char *) sqlite3_column_text(statement, 8); NSString *field7Str = [[NSString alloc]initWithUTF8String:field7]; char *field8 = (char *) sqlite3_column_text(statement, 4); NSString *field8Str = [[NSString alloc]initWithUTF8String:field8]; char *field9 = (char *) sqlite3_column_text(statement, 11); NSString *field9Str = [[NSString alloc]initWithUTF8String:field9]; char *field10 = (char *) sqlite3_column_text(statement, 12); NSString *field10Str = [[NSString alloc]initWithUTF8String:field10]; char *field11 = (char *) sqlite3_column_text(statement, 13); NSString *coverFilePath = [[NSString alloc]initWithUTF8String:field11]; char *field12 = (char *) sqlite3_column_text(statement, 14); NSString *circleFilePath = [[NSString alloc]initWithUTF8String:field12]; NSString *House = [[NSString alloc] initWithFormat:@"%@",field1Str];//House NSString *StickerCollection = [[NSString alloc]initWithFormat:@"%@",field2Str];//Sticker Collection NSString *sCurrentTickets = [[NSString alloc] initWithFormat:@"%@",field6Str];//Current Tickets stickerarray = [[NSMutableArray alloc] initWithArray:[StickerCollection componentsSeparatedByString:@" "]]; totaltickets = field8Str; self.tickets.text = sCurrentTickets; completecount = [field7Str integerValue]; IsItComplete = field3Str; stickercount = [field4Str integerValue]; [self.message setTitle:field9Str forState:UIControlStateNormal]; if ([field10Str integerValue] == 1) { self.message.alpha = 1; } else { self.message.alpha = 0.1; } NSLog(@"This is the sticker count: %d", stickercount); NSLog(@"This is the complete count: %d", completecount); NSBundle* bundle = [NSBundle mainBundle]; if ([coverFilePath isEqualToString:@"Blank"]) { self.background.backgroundColor = [UIColor scrollViewTexturedBackgroundColor]; self.background.image = NULL; } else { self.background.image = [UIImage imageWithContentsOfFile:[bundle pathForResource:coverFilePath ofType:nil]]; } if (![circleFilePath isEqualToString:@"Blank"]) { for (int i = 0; i < 16; i++) { [[self returncircle:i] setImage:[UIImage imageWithContentsOfFile:[bundle pathForResource:coverFilePath ofType:nil]] forState:UIControlStateNormal]; } } } } } -(void)leaderboardsystem { NSString *nexttargetsql = [NSString stringWithFormat:@"SELECT Name FROM Children WHERE Completed > %d OR (Completed = %d AND Current_Stickers > %d) ORDER BY Completed ASC, Current_Stickers ASC LIMIT 1",completecount,completecount,stickercount]; //Queries table for the childs name and returns more data. NSString *behindyousql = [NSString stringWithFormat:@"SELECT Name FROM Children WHERE Completed < %d OR (Completed = %d AND Current_Stickers < %d) ORDER BY Completed DESC, Current_Stickers DESC LIMIT 1",completecount,completecount,stickercount]; sqlite3_stmt *statement; if (sqlite3_prepare_v2(Childdb, [nexttargetsql UTF8String], -1, &statement, nil)==SQLITE_OK) { while (sqlite3_step(statement)==SQLITE_ROW) { char *ffield1 = (char *) sqlite3_column_text(statement, 0); NSString *ffield1Str = [[NSString alloc]initWithUTF8String:ffield1]; nexttarget.text = ffield1Str; } } if (sqlite3_prepare_v2(Childdb, [behindyousql UTF8String], -1, &statement, nil)==SQLITE_OK) { while (sqlite3_step(statement)==SQLITE_ROW) { char *field1 = (char *) sqlite3_column_text(statement, 0); NSString *field1Str = [[NSString alloc]initWithUTF8String:field1]; behindyou.text = field1Str; } } } -(void)leaderboard:(UIBarButtonItem *)leaderboard { [UIView transitionWithView:Hub duration:0.5 options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{ //redeem.hidden = YES; if (!Hub.leaderUp) { self.navigationItem.rightBarButtonItem.title = @"Hub"; [self leaderboardsystem]; Hub.leaderUp = YES; Hub.completecount.text = [[NSNumber numberWithInt:completecount]stringValue]; Hub.stickercount.text = [[NSNumber numberWithInt:stickercount]stringValue]; } else { self.navigationItem.rightBarButtonItem.title = @"Leaderboard"; Hub.leaderUp = NO; } } completion:NULL]; } - (NSString *)documentsPathForFileName//returns the filepath for the image { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); NSString *documentsPath = [paths objectAtIndex:0]; return [documentsPath stringByAppendingPathComponent:[self title]]; } -(void)LoadPicture { NSData *pngData = [NSData dataWithContentsOfFile:[self documentsPathForFileName]]; displaypicture.image = [UIImage imageWithCGImage:[UIImage imageWithData:pngData].CGImage scale:1.0 orientation:UIImageOrientationRight];; } -(void)UpdatePicture //update picture, if value has been incremented { NSData *imageData = UIImagePNGRepresentation([displaypicture image]); NSString *filePath = [self documentsPathForFileName];//Add the file name [imageData writeToFile:filePath atomically:YES]; //Write the file } -(void)updatetable:(NSString*)sql { char *err; if (sqlite3_exec(Childdb, [sql UTF8String], NULL, NULL, &err)!=SQLITE_OK) { sqlite3_close(Childdb); NSAssert(0, @"Could not update Table"); } else { NSLog(@"Table updated"); } } -(void)updatestickercollectioncomplete//when the last sticker is collected is must update table bool. { IsItComplete = @"1"; //bool value, its currently completed. NSString *sql = [NSString stringWithFormat:@"UPDATE Children SET 'Complete' = %d WHERE Name = '%@'", [IsItComplete integerValue] ,name]; [self updatetable:sql]; } -(void)viewDidDisappear:(BOOL)animated { NSLog(@"Database closed"); sqlite3_close(Childdb); } -(void)UpdatecurrentTickets //update table, if value has been incremented { NSString *sql = [NSString stringWithFormat:@"UPDATE Children SET 'Current Tickets' = %d, 'Sticker Collection' = '%@', 'Tickets Gathered' = '%d', 'Current_Stickers' = %d WHERE Name = '%@'", [self.tickets.text integerValue],//The current ticket [self.stickerarray componentsJoinedByString:@" "], [totaltickets integerValue], stickercount,name]; [self updatetable:sql];//sends query to update table method. } -(void)openDB { if (sqlite3_open([[self filePath] UTF8String], &Childdb)!= SQLITE_OK) { sqlite3_close(Childdb); NSAssert(0, @"Database failed to open"); } else { NSLog(@"Database Opened"); } } -(NSString*) filePath { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); return [[paths objectAtIndex:0] stringByAppendingPathComponent:@"bp.sql"]; } - (void)viewDidLoad { [super viewDidLoad]; self.title = name; //set the title to the child [self LoadPicture]; // stickerarray = [[NSMutableArray alloc] initWithArray:[[theDataObject.stickers objectAtIndex:[childindex integerValue]] componentsSeparatedByString:@" "]]; // calls the hiddeCircles method that reveals the circles they have achieved. animation = false; //sets a false value for animation because no animations. //The app doesn't update the array yet. //circle1.hidden = true; // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @endFilename : TableViewStory/ChildrenTableViewCell.m // // ChildrenTableViewCell.m // TableViewStory // // Created by Oliver Jarrett on 28/10/2012. // Copyright (c) 2012 Oliver Jarrett. All rights reserved. // #import "ChildrenTableViewCell.h" @implementation ChildrenTableViewCell @synthesize childname; - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { // Initialization code } return self; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } @end Filename : TableViewStory/QRCodeAddView.m // // QRCodeAddView.m // TableViewStory // // Created by Oliver Jarrett on 06/03/2013. // Copyright (c) 2013 Oliver Jarrett. All rights reserved. // #import "QRCodeAddView.h" @interface QRCodeAddView () @property (nonatomic) BOOL *DoesitHaveMessage; @end @implementation QRCodeAddView - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } -(IBAction)hypertext:(id)sender { NSString* textmodified = [self.nameField.text stringByReplacingOccurrencesOfString:@" " withString:@"+"]; NSString* url = [[NSString alloc]initWithFormat:@"http://qrfree.kaywa.com/?l=1&s=8&d=%@",textmodified]; [[UIApplication sharedApplication]openURL:[NSURL URLWithString:url]]; } -(void)UpdateTable:(id)sql { char *err; if (sqlite3_exec(qrdb, [sql UTF8String], NULL, NULL, &err)!=SQLITE_OK) { self.errorLabel.hidden = false; } else { NSLog(@"Table updated"); //Table updated, so dismiss view controller and run viewwillappear on predecessor. [self.presentingViewController viewWillAppear:YES]; [self dismissModalViewControllerAnimated:YES]; } } -(int)valueOfIndex { switch (self.valueSegment.selectedSegmentIndex) { case 0: return 1; break; case 1: return 2; break; case 2: return 5; break; case 3: return 10; break; default: return NULL; break; } } -(IBAction)Done:(id)sender { //checks whether its edit mode or create mode. if (self.nameField.hidden) { //if the namefield is hidden then its in edit mode NSString *sql = [NSString stringWithFormat:@"UPDATE QR SET Message = '%@', Value = '%d' WHERE Title = '%@'",self.messageField.text,[self valueOfIndex],self.nameField.text]; [self UpdateTable:sql]; } else { //its in create mode. if ([self.messageField.text isEqualToString:@""]) { //checks whether its null, then change query. NSString *sql = [NSString stringWithFormat:@"INSERT INTO QR('Title', 'Message', 'Last', 'Count', 'Last_Date', 'Value') VALUES ('%@', '%@', '%@', %d, '%@', '%d')", self.nameField.text, @" ", @" ", 0 , @" ",[self valueOfIndex]]; [self UpdateTable:sql]; } else { NSString *sql = [NSString stringWithFormat:@"INSERT INTO QR('Title', 'Message', 'Last', 'Count', 'Last_Date', 'Value') VALUES ('%@', '%@', '%@', %d, '%@', '%d')", self.nameField.text, self.messageField.text, @" ", 0 , @" ",[self valueOfIndex]]; [self UpdateTable:sql]; } } } -(NSString*) filePath { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); return [[paths objectAtIndex:0] stringByAppendingPathComponent:@"bp.sql"]; } -(void)openDB { if (sqlite3_open([[self filePath] UTF8String], &qrdb)!= SQLITE_OK) { sqlite3_close(qrdb); NSAssert(0, @"Database failed to open"); } else { NSLog(@"Database Opened"); } } -(void)manageMode { self.bar.topItem.title = [NSString stringWithFormat:@"Editting QR Code: %@", self.nameField.text]; self.nameField.hidden=TRUE; } -(IBAction)Cancel:(id)sender { [self dismissModalViewControllerAnimated:YES]; } - (void)viewDidLoad { [super viewDidLoad]; [self openDB]; // Do any additional setup after loading the view from its nib. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end Filename : TableViewStory/QRCodeTableCell.m // // QRCodeTableCell.m // TableViewStory // // Created by Oliver Jarrett on 05/03/2013. // Copyright (c) 2013 Oliver Jarrett. All rights reserved. // #import "QRCodeTableCell.h" @implementation QRCodeTableCell - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { // Initialization code [self setSelectionStyle:UITableViewCellSelectionStyleNone]; } return self; } -(void)openDB { if (sqlite3_open([[self filePath] UTF8String], &qrdb)!= SQLITE_OK) { sqlite3_close(qrdb); NSAssert(0, @"Database failed to open"); } else { NSLog(@"Database Opened"); } } -(NSString*) filePath { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); return [[paths objectAtIndex:0] stringByAppendingPathComponent:@"bp.sql"]; } -(void)UpdateDatabase//update table, if value has been incremented { NSString *sql = [NSString stringWithFormat:@"UPDATE QR SET Count = %d WHERE Title = '%@'",[self.count.text integerValue], self.title.text]; char *err; if (sqlite3_exec(qrdb, [sql UTF8String], NULL, NULL, &err)!=SQLITE_OK) { sqlite3_close(qrdb); NSAssert(0, @"Could not update Table"); } else { NSLog(@"Table updated"); } } -(void)Increment:(id)sender { if (self.increment.value >=10) { self.increment.stepValue = 10; } else { self.increment.stepValue = 1; } self.count.text = [[NSNumber numberWithDouble:self.increment.value]stringValue]; [self openDB]; [self UpdateDatabase]; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } @end Filename : TableViewStory/QRCodeTableView.m // // QRCodeTableView.m // TableViewStory // // Created by Oliver Jarrett on 05/03/2013. // Copyright (c) 2013 Oliver Jarrett. All rights reserved. // #import "QRCodeAddView.h" #import "QRCodeTableView.h" #import "QRCodeTableCell.h" @interface QRCodeTableView () @property (nonatomic) BOOL editting; @property (nonatomic, strong) NSMutableArray *name; @property (nonatomic, strong) NSMutableArray *message; @property (nonatomic, strong) NSMutableArray *lastused; @property (nonatomic, strong) NSMutableArray *count; @end @implementation QRCodeTableView - (id)initWithStyle:(UITableViewStyle)style { self = [super initWithStyle:style]; if (self) { // Custom initialization } return self; } -(void)setName:(NSMutableArray *)name { _name = name; } -(void)setMessage:(NSMutableArray *)message { _message = message; } -(void)setCount:(NSMutableArray *)count { _count = count; } -(void)setLastused:(NSMutableArray *)lastused { _lastused = lastused; } -(NSString*) filePath { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); return [[paths objectAtIndex:0] stringByAppendingPathComponent:@"bp.sql"]; } -(void)tableSetUp { [self openDB]; NSString *sql = [NSString stringWithFormat:@"SELECT * FROM QR"]; sqlite3_stmt *statement; if (sqlite3_prepare_v2(qrdb, [sql UTF8String], -1, &statement, nil)==SQLITE_OK) { while (sqlite3_step(statement)==SQLITE_ROW) { char *field1 = (char *) sqlite3_column_text(statement, 0); NSString *field1Str = [[NSString alloc]initWithUTF8String:field1]; char *field2 = (char *) sqlite3_column_text(statement, 1); NSString *field2Str = [[NSString alloc]initWithUTF8String:field2]; char *field3 = (char *) sqlite3_column_text(statement, 2); NSString *field3Str = [[NSString alloc]initWithUTF8String:field3]; char *field4 = (char *) sqlite3_column_text(statement, 3); NSString *field4Str = [[NSString alloc]initWithUTF8String:field4]; char *field5 = (char *) sqlite3_column_text(statement, 4); NSString *field5Str = [[NSString alloc]initWithUTF8String:field5]; NSString *str = [[NSString alloc] initWithFormat:@"%@",field1Str]; NSString *str2 = [[NSString alloc]initWithFormat:@"%@",field2Str]; NSString *str3 = [[NSString alloc] initWithFormat:@"%@",field3Str]; NSString *str4 = [[NSString alloc] initWithFormat:@"%@",field4Str]; NSString *str5 = [[NSString alloc] initWithFormat:@"%@",field5Str]; [self.name addObject:str]; [self.message addObject:str2]; [self.lastused addObject:str3]; [self.count addObject:str4]; } } } -(void)openDB { if (sqlite3_open([[self filePath] UTF8String], &qrdb)!= SQLITE_OK) { sqlite3_close(qrdb); NSAssert(0, @"Database failed to open"); } else { NSLog(@"Database Opened"); } } -(IBAction)editting:(id)sender { if (!self.editting) { self.editting = YES; self.navigationItem.hidesBackButton = YES; self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(Add:)]; //Displays add button over the back button [self setEditing:YES animated:YES]; // [self.firstTable setEditing:YES animated:YES]; } else { self.editting = NO; self.navigationItem.hidesBackButton = NO; self.navigationItem.leftBarButtonItem = NO; [self setEditing:NO animated:YES]; // [self.firstTable setEditing:NO animated:YES]; } } -(void)Add:(id)sender { QRCodeAddView *addqr = [[QRCodeAddView alloc]init]; addqr.modalPresentationStyle = UIModalPresentationFormSheet; [self presentModalViewController:addqr animated:YES]; } -(void)viewWillAppear:(BOOL)animated { self.name = [[NSMutableArray alloc]init]; self.message = [[NSMutableArray alloc]init]; self.count = [[NSMutableArray alloc]init]; self.lastused = [[NSMutableArray alloc]init]; NSLog(@"THis was ran oh boy"); [self tableSetUp]; [[self tableView]reloadData]; } - (void)viewDidLoad { [super viewDidLoad]; // Uncomment the following line to preserve selection between presentations. // self.clearsSelectionOnViewWillAppear = NO; // Uncomment the following line to display an Edit button in the navigation bar for this view controller. // self.navigationItem.rightBarButtonItem = self.editButtonItem; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { #warning Potentially incomplete method implementation. // Return the number of sections. return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { #warning Incomplete method implementation. // Return the number of rows in the section. return [self.name count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"QRTableCell"; QRCodeTableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[QRCodeTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } cell.title.text = [self.name objectAtIndex:indexPath.row]; cell.description.text = [self.message objectAtIndex:indexPath.row]; cell.count.text = [self.count objectAtIndex:indexPath.row]; cell.lastused.text = [self.lastused objectAtIndex:indexPath.row]; cell.increment.value = [cell.count.text integerValue]; if (cell.increment.value >= 10) { cell.increment.stepValue = 10; } else { cell.increment.stepValue = 1; } // Configure the cell... return cell; } /* // Override to support conditional editing of the table view. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the specified item to be editable. return YES; } */ // Override to support editing the table view. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { // Delete the row from the data source NSString *sql = [NSString stringWithFormat:@"DELETE FROM QR WHERE Title = '%@' ",[self.name objectAtIndex:indexPath.row]]; //Queries table for the childs name and returns more data. sqlite3_stmt *statement; if (sqlite3_prepare_v2(qrdb, [sql UTF8String], -1, &statement, nil)==SQLITE_OK){ while (sqlite3_step(statement)==SQLITE_ROW) { } } [self.name removeObjectAtIndex:indexPath.row]; [self.message removeObjectAtIndex:indexPath.row]; [self.lastused removeObjectAtIndex:indexPath.row]; [self.count removeObjectAtIndex:indexPath.row]; [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; } } /* // Override to support rearranging the table view. - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { } */ /* // Override to support conditional rearranging of the table view. - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the item to be re-orderable. return YES; } */ #pragma mark - Table view delegate -(int)valueSegment:(NSString*)name { NSString *sql = [NSString stringWithFormat:@"SELECT Value FROM QR WHERE Title = '%@'",name]; NSString *value; sqlite3_stmt *statement; if (sqlite3_prepare_v2(qrdb, [sql UTF8String], -1, &statement, nil)==SQLITE_OK) { while (sqlite3_step(statement)==SQLITE_ROW) { char *field1 = (char *) sqlite3_column_text(statement, 0); value = [[NSString alloc]initWithUTF8String:field1]; } } return [self valueOfIndex:value]; } -(int)valueOfIndex:(NSString*)value { switch ([value integerValue]) { case 1: return 0; break; case 2: return 1; break; case 5: return 2; break; case 10: return 3; break; default: return NULL; break; } } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { QRCodeAddView *changeqr = [[QRCodeAddView alloc]init]; changeqr.modalPresentationStyle = UIModalPresentationFormSheet; [self presentModalViewController:changeqr animated:YES]; changeqr.nameField.text = [self.name objectAtIndex:indexPath.row]; changeqr.messageField.text = [self.message objectAtIndex:indexPath.row]; changeqr.valueSegment.selectedSegmentIndex = [self valueSegment:[self.name objectAtIndex:indexPath.row]]; [changeqr manageMode]; // 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]; */ } @end Filename : TableViewStory/TableSplitViewController.m // // TableSplitViewController.m // TableViewStory // // Created by Oliver Jarrett on 30/01/2013. // Copyright (c) 2013 Oliver Jarrett. All rights reserved. // #import "TableSplitViewController.h" #import "ChildrenDetailViewController.h" #import "TeacherSplitViewController.h" @interface TableSplitViewController () @property NSMutableArray *coverFilePath; @property (strong) IBOutlet UIImageView *background; @property (weak) NSUserDefaults *teacherDetails; @end @implementation TableSplitViewController @synthesize name; @synthesize childnamelabel, teachernamelabel, displaypicture; @synthesize submit, passwordfield, LogInButton, swipeleft, swiperight; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization [self animation]; [self returnanimation]; } return self; } -(void)setViewUp { if ([firstController.listofnames count] != 0 ) {//checks if the array is empty to avoid errors. teachernamelabel.hidden = TRUE; childnamelabel.hidden = FALSE; passwordfield.hidden = FALSE; LogInButton.hidden = FALSE; [self setNameLabel: [firstController.listofnames objectAtIndex:0] Child:[NSNumber numberWithInt:1]index:0]; firstTable.alpha = 1.0; [self createTeacherButton]; } else {//if it is empty then hide everything and just display an empty table. teachernamelabel.hidden = TRUE; childnamelabel.hidden = TRUE; passwordfield.hidden = TRUE; LogInButton.hidden = TRUE; } swipeleft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(PressedTeacherButton:)]; [swipeleft setDirection:(UISwipeGestureRecognizerDirectionLeft)]; [[self view] addGestureRecognizer:swipeleft]; swiperight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(Revert)]; [swiperight setDirection:(UISwipeGestureRecognizerDirectionRight)]; [[self view] addGestureRecognizer:swiperight]; } -(void)createTeacherButton { self.Teacherbutton = [[UIBarButtonItem alloc]initWithTitle:@"Teacher" style:UIBarButtonSystemItemSearch target:self action:@selector(PressedTeacherButton:)]; [self.Teacherbutton setTintColor:[UIColor orangeColor]]; self.navigationItem.rightBarButtonItem = self.Teacherbutton; } -(void)viewDidAppear:(BOOL)animated { NSLog(@"%@",IsAChild); } - (NSString *)documentsPathForFileName//returns the filepath for the image { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); NSString *documentsPath = [paths objectAtIndex:0]; return [documentsPath stringByAppendingPathComponent:childnamelabel.text]; } -(void)LoadPicture { displaypicture.hidden = FALSE; NSData *pngData = [NSData dataWithContentsOfFile:[self documentsPathForFileName]]; displaypicture.image = [UIImage imageWithCGImage:[UIImage imageWithData:pngData].CGImage scale:1.0 orientation:UIImageOrientationRight];; } -(void)viewWillAppear:(BOOL)animated { firstController = [[ChildrenTableViewController alloc] initWithStyle:UITableViewStyleGrouped]; [self tableSetUp]; [firstTable setDataSource:firstController]; [firstTable setDelegate:firstController]; firstController.view = firstController.tableView; [firstController setDelegate1:self]; [firstTable reloadData]; [self setViewUp]; //[self Revert]; //remove password textfield text self.passwordfield.text = NULL; } - (void)viewDidLoad { [super viewDidLoad]; [self openDB]; IsAChild = [NSNumber numberWithInt:1]; [self createTable:@"Children" withField1:@"Name" withField2:@"Password" withField3:@"House" withField4:@"Sticker Collection" withField5:@"Tickets Gathered" withField6:@"Tickets Removed" withField7:@"Last Ticket Scanned" withField8:@"Current Tickets" withField9:@"Completed" withField10:@"Complete" withField11:@"Current_Stickers" withField12:@"Message" withField13:@"Showmessage" withField14:@"Cover" withField15:@"Circle"]; [self createQRTable:@"QR" withField1:@"Title" withField2:@"Message" withField3:@"Last" withField4:@"Count" withField5:@"Last_Date" withField6:@"Value"]; // Do any additional setup after loading the view. } -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([[segue identifier] isEqualToString:@"ShowChildrenDetails"]) { ChildrenDetailViewController *detailViewController = [segue destinationViewController]; NSIndexPath *myIndexPath = [firstController.tableView indexPathForSelectedRow]; detailViewController.name = self.childnamelabel.text; } else if ([[segue identifier] isEqualToString:@"ShowAdminDetails"]) { TeacherSplitViewController *AdminViewController = [segue destinationViewController]; } } -(void)tableSetUp { [self openDB]; self.coverFilePath = [[NSMutableArray alloc]init]; NSString *sql = [NSString stringWithFormat:@"SELECT Name, Cover FROM Children ORDER BY Name ASC"]; sqlite3_stmt *statement; if (sqlite3_prepare_v2(Childdb, [sql UTF8String], -1, &statement, nil)==SQLITE_OK) { while (sqlite3_step(statement)==SQLITE_ROW) { char *field1 = (char *) sqlite3_column_text(statement, 0); NSString *field1Str = [[NSString alloc]initWithUTF8String:field1]; char *field2 = (char *) sqlite3_column_text(statement, 1); NSString *field2Str = [[NSString alloc]initWithUTF8String:field2]; NSString *str = [[NSString alloc] initWithFormat:@"%@",field1Str]; NSLog(@"%@", str); [firstController.listofnames addObject:str]; [self.coverFilePath addObject:field2Str]; NSLog(@"%@",self.coverFilePath); } // self.childnamelabel.text = [firstController.listofnames objectAtIndex:0]; } } -(BOOL)checkPassword { BOOL *legit = false; NSString *sql = [NSString stringWithFormat:@"SELECT Password FROM Children WHERE Name = '%@'",self.childnamelabel.text]; sqlite3_stmt *statement; if (sqlite3_prepare_v2(Childdb, [sql UTF8String], -1, &statement, nil)==SQLITE_OK) { while (sqlite3_step(statement)==SQLITE_ROW) { char *field1 = (char *) sqlite3_column_text(statement, 0); NSString *field1Str = [[NSString alloc]initWithUTF8String:field1]; if ([self.passwordfield.text isEqualToString:field1Str]||[field1Str isEqualToString:@""]) { legit = true; } } } return legit; } -(void)openDB { //open Child Table if (sqlite3_open([[self filePath] UTF8String], &Childdb)!= SQLITE_OK) { sqlite3_close(Childdb); NSAssert(0, @"Database failed to open"); } else { NSLog(@"Database Opened"); } //open QRCode Table if (sqlite3_open([[self filePath] UTF8String], &qrdb)!= SQLITE_OK) { sqlite3_close(qrdb); NSAssert(0, @"Database failed to open"); } else { NSLog(@"Database Opened"); } } -(NSString*) filePath { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); return [[paths objectAtIndex:0] stringByAppendingPathComponent:@"bp.sql"]; } -(void)viewDidDisappear:(BOOL)animated { sqlite3_close(Childdb); } -(void)Revert { //firstTable.hidden = FALSE; [UIView animateWithDuration:0.3 animations:^() { firstTable.alpha = 1; }]; [self setViewUp]; [self returnanimation]; } -(void)returnanimation { CGRect textframe = passwordfield.frame; textframe.origin.x = 454; // new x coordinate textframe.origin.y = 388; // new y coordinate CGRect submitframe = submit.frame; submitframe.origin.x = 640; // new x coordinate submitframe.origin.y = 387; // new y coordinate [UIView animateWithDuration:0.25 animations:^{ passwordfield.frame = textframe; submit.frame = submitframe; } ]; } -(void)animation { //CGRect labelframe = childnamelabel.frame; //labelframe.origin.x = 335; // new x coordinate //labelframe.origin.y = 359; // new y coordinate CGRect textframe = passwordfield.frame; textframe.origin.x = 294; // new x coordinate textframe.origin.y = 388; // new y coordinate CGRect submitframe = submit.frame; submitframe.origin.x = 480; // new x coordinate submitframe.origin.y = 387; // new y coordinate [UIView animateWithDuration:0.25 animations:^{ // childnamelabel.frame = labelframe; passwordfield.frame = textframe; submit.frame = submitframe; }]; } // if (finished) { -(void) createQRTable:(NSString *)tableName withField1:(NSString *)field1 withField2:(NSString *)field2 withField3:(NSString *)field3 withField4:(NSString *)field4 withField5:(NSString *)field5 withField6:(NSString *)field6; { NSString *sql = [NSString stringWithFormat: @"CREATE TABLE IF NOT EXISTS '%@' ('%@'" "TEXT PRIMARY KEY, '%@' TEXT, '%@' TEXT, '%@' INTEGER, '%@' TEXT, '%@' INTEGER);", tableName, field1, field2, field3, field4, field5, field6]; char *err; if (sqlite3_exec(qrdb, [sql UTF8String], NULL, NULL, &err) != SQLITE_OK) { sqlite3_close(qrdb); NSAssert(0, @"Could not create table"); } else { NSLog(@"Table Created"); } } -(void) createTable: (NSString*) tableName withField1:(NSString*)field1 withField2:(NSString*)field2 withField3:(NSString*)field3 withField4:(NSString*)field4 withField5:(NSString*)field5 withField6:(NSString*)field6 withField7:(NSString*)field7 withField8:(NSString *)field8 withField9:(NSString *)field9 withField10:(NSString *)field10 withField11:(NSString *)field11 withField12:(NSString *)field12 withField13:(NSString *)field13 withField14:(NSString *)field14 withField15:(NSString *)field15; { char *err; NSString *sql = [NSString stringWithFormat: @"CREATE TABLE IF NOT EXISTS '%@' ('%@'" "TEXT PRIMARY KEY, '%@' TEXT, '%@' TEXT, '%@' TEXT, '%@' INTEGER, '%@' INTEGER, '%@' TEXT, '%@' INTEGER, '%@' INTEGER, '%@' INTEGER, '%@' INTEGER, '%@' TEXT, '%@' INTEGER, '%@' TEXT, '%@' TEXT);", tableName, field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13, field14, field15]; if (sqlite3_exec(Childdb, [sql UTF8String], NULL, NULL, &err) != SQLITE_OK) { sqlite3_close(Childdb); NSAssert(0, @"Could not create table"); } else { NSLog(@"Table Created"); } } -(IBAction)PressedTeacherButton: (UIBarButtonItem*) Teacherbutton { //grab the NSUserDefaults keys self.teacherDetails = [NSUserDefaults standardUserDefaults]; [UIView animateWithDuration:0.2 animations:^() { firstTable.alpha = 0; }]; //passes the name of the teacher and returns a 0 to notify this isn't a child. [self setNameLabel: [self.teacherDetails stringForKey:@"teacherName"] Child:[NSNumber numberWithInt:0] index:nil]; // self.navigationItem.rightBarButtonItem = self.Children = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(Revert)]; self.navigationItem.rightBarButtonItem = self.Children = [[UIBarButtonItem alloc]initWithTitle:@"Pupils" style:UIBarButtonItemStyleDone target:self action:@selector(Revert)]; } -(void)shakeanimation { CABasicAnimation *shake = [CABasicAnimation animationWithKeyPath:@"position"]; [shake setDuration:0.1]; [shake setRepeatCount:2]; [shake setAutoreverses:YES]; [shake setFromValue:[NSValue valueWithCGPoint: CGPointMake(self.passwordfield.center.x - 5,self.passwordfield.center.y)]]; [shake setToValue:[NSValue valueWithCGPoint: CGPointMake(self.passwordfield.center.x + 5, self.passwordfield.center.y)]]; [self.passwordfield.layer addAnimation:shake forKey:@"position"]; } -(IBAction)PressedLogInButton:(UIButton*)LogInButton { if (IsAChild == [NSNumber numberWithInt:1]) { //person logging in is a child //checks password is legit if ([self checkPassword]) { //passwor is legit, log child in. [self performSegueWithIdentifier:@"ShowChildrenDetails" sender:nil]; } else { //incorrect password shake passwordfield. [self shakeanimation]; } } else if (IsAChild == [NSNumber numberWithInt:0]) { //person logging in is the admin //checks whether the password matches admin password //checks admin password is legit OR if password isn't set. if ([self.passwordfield.text isEqualToString:[self.teacherDetails stringForKey:@"teacherPass"]]||![self.teacherDetails stringForKey:@"teacherPass"]) { [self performSegueWithIdentifier:@"ShowAdminDetails" sender:nil]; } else { //incorrect password provided, so do the shake animation [self shakeanimation]; } } } -(void)setCover:(id)coverFilePath { NSBundle* bundle = [NSBundle mainBundle]; self.background.hidden = FALSE; if ([coverFilePath isEqualToString:@"Blank"]) { self.background.backgroundColor = [UIColor scrollViewTexturedBackgroundColor]; self.background.image = NULL; } else { self.background.image = [UIImage imageWithContentsOfFile:[bundle pathForResource:coverFilePath ofType:nil]]; } } - (void) setNameLabel:(NSString *)sender Child:(NSNumber *)Child index:(int)row { if (Child == [NSNumber numberWithInt:1]) { childnamelabel.text = sender; [self setCover:[self.coverFilePath objectAtIndex:row]]; [self LoadPicture]; } else { [UIView animateWithDuration:0.25 animations:^{ teachernamelabel.text = sender; teachernamelabel.hidden = FALSE; childnamelabel.hidden = TRUE; self.background.hidden = TRUE; displaypicture.hidden = TRUE; }completion:^(BOOL finished){ [self animation]; passwordfield.hidden = FALSE; LogInButton.hidden = FALSE; } ]; } IsAChild = Child; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end Filename : TableViewStory/TableViewStoryAppDelegate.m // // TableViewStoryAppDelegate.m // TableViewStory // // Created by Oliver Jarrett on 28/10/2012. // Copyright (c) 2012 Oliver Jarrett. All rights reserved. // #import "TableViewStoryAppDelegate.h" @implementation TableViewStoryAppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // self.qrwindow.rootViewController = self.viewController; //[self.qrwindow makeKeyAndVisible]; // force view class to load so it may be referenced directly from NIB [ZBarReaderView class]; return YES; } - (id) init; { return [super init]; } - (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:. } @end Filename : TableViewStory/TeacherAddChildController.m // // TeacherAddChildController.m // TableViewStory // // Created by Oliver Jarrett on 10/02/2013. // Copyright (c) 2013 Oliver Jarrett. All rights reserved. // #import "TeacherAddChildController.h" @interface TeacherAddChildController () @end @implementation TeacherAddChildController @synthesize Name, Password, House; -(NSString*) filePath { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); return [[paths objectAtIndex:0] stringByAppendingPathComponent:@"bp.sql"]; } -(IBAction)cancel:(id)sender { //user has selected the cancel button. [self dismissModalViewControllerAnimated:YES]; } -(IBAction)saveEntry:(id)sender { NSString *name = Name.text; NSString *password = Password.text; NSString *sql = [NSString stringWithFormat:@"INSERT INTO Children('Name', 'Password', 'House', 'Sticker Collection', 'Tickets Gathered', 'Tickets Removed', 'Last Ticket Scanned', 'Current Tickets', 'Completed', 'Complete', 'Current_Stickers', 'Message', 'Showmessage', 'Cover', 'Circle') VALUES ('%@', '%@', '%@', '%@', '%d', '%d', '%@', '%d', '%d', '%d', '%d', '%@', '%d','%@','%@')", name, password, @"House1" ,@"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", 0, 0, @"None", 0, 0, 0, 0, @" ", 1,@"Blank", @"Blank"]; char *err; if (sqlite3_exec(Childdb, [sql UTF8String], NULL, NULL, &err)!=SQLITE_OK) { NSLog(@"Could not update Table"); //show the label to make teacher aware of the error. self.errorLabel.hidden = false; } else { //if theres no problems then the child is added. NSLog(@"Table updated"); //run the viewwillappear function in the view controller the presented this controller [self.presentingViewController viewWillAppear:NO]; //dismiss this view controller. [self dismissModalViewControllerAnimated:YES]; } } -(void)openDB { if (sqlite3_open([[self filePath] UTF8String], &Childdb)!= SQLITE_OK) { sqlite3_close(Childdb); NSAssert(0, @"Database failed to open"); } else { NSLog(@"Database Opened"); } } - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; [self openDB]; // Do any additional setup after loading the view from its nib. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end Filename : TableViewStory/TeacherEditSettings.m // // TeacherEditSettings.m // TableViewStory // // Created by Oliver Jarrett on 28/03/2013. // Copyright (c) 2013 Oliver Jarrett. All rights reserved. // #import "TeacherEditSettings.h" @interface TeacherEditSettings () @end @implementation TeacherEditSettings - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; self.prefs = [NSUserDefaults standardUserDefaults]; //retrieving data from NSUserDefaults self.nameField.text = [self.prefs stringForKey:@"teacherName"]; self.passwordField.text = [self.prefs stringForKey:@"teacherPass"]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (IBAction)Save:(id)sender { // Storing data into NSUserDefaults [self.prefs setObject:self.nameField.text forKey:@"teacherName"]; [self.prefs setObject:self.passwordField.text forKey:@"teacherPass"]; [self.prefs synchronize]; [self dismissModalViewControllerAnimated:YES]; } - (IBAction)Cancel:(id)sender { [self dismissModalViewControllerAnimated:YES]; } @end Filename : TableViewStory/TeacherSplitTableCell.m // // TeacherSplitTableCell.m // TableViewStory // // Created by Oliver Jarrett on 07/02/2013. // Copyright (c) 2013 Oliver Jarrett. All rights reserved. // #import "TeacherSplitTableCell.h" @implementation TeacherSplitTableCell @synthesize childname; @synthesize totaltickets; - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { // Initialization code } return self; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } @end Filename : TableViewStory/TeacherSplitViewController.m // // TeacherSplitViewController.m // TableViewStory // // Created by Oliver Jarrett on 06/02/2013. // Copyright (c) 2013 Oliver Jarrett. All rights reserved. // #import "TeacherSplitViewController.h" #import "TeacherSplitPresentationView.h" #import "TeacherEditSettings.h" @interface TeacherSplitViewController () @property (nonatomic) TeacherSplitPresentationView *model; @property (nonatomic) BOOL editting; @end @implementation TeacherSplitViewController @synthesize firstTable; @synthesize editting; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (IBAction)editSettings:(id)sender { TeacherEditSettings *model = [[TeacherEditSettings alloc]initWithNibName:nil bundle:nil]; model.modalPresentationStyle = UIModalPresentationFormSheet; [self presentModalViewController:model animated:YES]; } -(IBAction)edit:(id)sender { if (!editting) { editting = YES; self.navigationItem.hidesBackButton = YES; self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(Add:)]; //Displays add button over the back button [self.firstTable setEditing:YES animated:YES]; } else { editting = NO; self.navigationItem.hidesBackButton = NO; self.navigationItem.leftBarButtonItem = NO; [self.firstTable setEditing:NO animated:YES]; } } -(IBAction)Add:(id)sender { TeacherAddChildController *addchild = [[TeacherAddChildController alloc]initWithNibName:nil bundle:nil]; addchild.modalPresentationStyle = UIModalPresentationFormSheet; [self presentModalViewController:addchild animated:YES]; } -(void)Childview:(NSInteger *)sender { TeacherSplitPresentationView *model = [[TeacherSplitPresentationView alloc]initWithNibName:nil bundle:nil]; model.modalPresentationStyle = UIModalPresentationFormSheet; model.name = [firstController.listofnames objectAtIndex:sender]; [self presentModalViewController:model animated:YES]; } -(void)tableSetUp { [self openDB]; NSString *sql = [NSString stringWithFormat:@"SELECT * FROM Children ORDER BY Current_Stickers DESC"]; sqlite3_stmt *statement; if (sqlite3_prepare_v2(Childdb, [sql UTF8String], -1, &statement, nil)==SQLITE_OK) { while (sqlite3_step(statement)==SQLITE_ROW) { char *field1 = (char *) sqlite3_column_text(statement, 0); NSString *field1Str = [[NSString alloc]initWithUTF8String:field1]; char *field2 = (char *) sqlite3_column_text(statement, 4); NSString *field2Str = [[NSString alloc]initWithUTF8String:field2]; char *field3 = (char *) sqlite3_column_text(statement, 5); NSString *field3Str = [[NSString alloc]initWithUTF8String:field3]; char *field4 = (char *) sqlite3_column_text(statement, 3); NSString *field4Str = [[NSString alloc]initWithUTF8String:field4]; NSString *str = [[NSString alloc] initWithFormat:@"%@",field1Str]; NSString *str2 = [[NSString alloc]initWithFormat:@"%@",field2Str]; NSString *str3 = [[NSString alloc] initWithFormat:@"%@",field3Str]; NSString *str4 = [[NSString alloc] initWithFormat:@"%@",field4Str]; [firstController.listofnames addObject:str]; [firstController.listoftickets addObject:[NSNumber numberWithInt:[str2 integerValue]-[str3 integerValue]]]; [firstController.stickers addObject:str4]; } } } -(void)openDB { if (sqlite3_open([[self filePath] UTF8String], &Childdb)!= SQLITE_OK) { sqlite3_close(Childdb); NSAssert(0, @"Database failed to open"); } else { NSLog(@"Database Opened"); } } -(NSString*) filePath { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); return [[paths objectAtIndex:0] stringByAppendingPathComponent:@"bp.sql"]; } -(void)setIsitQRCodeView:(BOOL *)IsitQRCodeView { _IsitQRCodeView = IsitQRCodeView; [self controllerSetup]; } -(void)viewWillAppear:(BOOL)animated { [self controllerSetup]; } -(void)controllerSetup { firstController = [[TeacherSplitTableController alloc] initWithStyle:UITableViewStyleGrouped]; [firstTable setDataSource:firstController]; [firstTable setDelegate:firstController]; firstController.view = firstController.tableView; [firstController setDelegate:self]; [self tableSetUp]; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(IBAction)tester: (UIButton*) tester{ TeacherSplitPresentationView *model = [[TeacherSplitPresentationView alloc]initWithNibName:nil bundle:nil]; model.modalPresentationStyle = UIModalPresentationFormSheet; [self presentModalViewController:model animated:YES]; } @end Filename : TableViewStory/main.m // // main.m // TableViewStory // // Created by Oliver Jarrett on 28/10/2012. // Copyright (c) 2012 Oliver Jarrett. All rights reserved. // #import #import "TableViewStoryAppDelegate.h" int main(int argc, char *argv[]) { @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([TableViewStoryAppDelegate class])); int retVal = UIApplicationMain(argc, argv, nil, nil); return retVal; } } Filename : TableViewStory/ChangePictureCell.h // // ChangePictureCell.h // TableViewStory // // Created by Oliver Jarrett on 22/02/2013. // Copyright (c) 2013 Oliver Jarrett. All rights reserved. // #import @interface ChangePictureCell : UITableViewCell @property (nonatomic) IBOutlet UIImageView *cover; @property (nonatomic) IBOutlet UIImageView *require; @property (nonatomic) IBOutlet UIImageView *tick; @property (nonatomic) IBOutlet UILabel *complete; @property (nonatomic) IBOutlet UILabel *stickers; @end Filename : TableViewStory/ChangePictureTable.h // // ChangePictureTable.h // TableViewStory // // Created by Oliver Jarrett on 22/02/2013. // Copyright (c) 2013 Oliver Jarrett. All rights reserved. // #import #import "sqlite3.h" @interface ChangePictureTable : UITableViewController { sqlite3 *Childdb; } @property (nonatomic) NSString *name; @end Filename : TableViewStory/ChildrenDetailControl.h // // ChildrenDetailControl.h // TableViewStory // // Created by Oliver Jarrett on 25/02/2013. // Copyright (c) 2013 Oliver Jarrett. All rights reserved. // #import @interface ChildrenDetailControl : UIView @property (nonatomic) BOOL *leaderUp; @property (nonatomic, strong) IBOutlet UIButton *scan; @property (nonatomic, strong) IBOutlet UIButton *redeem; @property (nonatomic, strong) IBOutlet UIButton *picture; @property (nonatomic, strong) IBOutlet UIButton *cover; @property (nonatomic) IBOutlet UIImageView *up; @property (nonatomic) IBOutlet UIImageView *down; @property (nonatomic) IBOutlet UILabel *nexttarget; @property (nonatomic) IBOutlet UILabel *you; @property (nonatomic) IBOutlet UILabel *behindyou; @property (nonatomic) IBOutlet UILabel *completelabel; @property (nonatomic) IBOutlet UILabel *stickerlabel; @property (nonatomic) IBOutlet UILabel *completecount; @property (nonatomic) IBOutlet UILabel *stickercount; @end Filename : TableViewStory/ChildrenDetailViewController.h // // ChildrenDetailViewController.h // TableViewStory // // Created by Oliver Jarrett on 28/10/2012. // Copyright (c) 2012 Oliver Jarrett. All rights reserved. // #import #import #import "QRReader.h" #import "sqlite3.h" #import "ChildrenDetailControl.h" @interface ChildrenDetailViewController : UIViewController { IBOutlet UIImageView *imageview; sqlite3 *Childdb; IBOutlet UILabel *tickets; IBOutlet UILabel *childname; NSMutableArray *stickerarray; NSMutableArray *touchDownStickers; IBOutlet UIButton *button1; IBOutlet UIButton *button2; IBOutlet UIButton *button3; IBOutlet UIButton *button4; IBOutlet UIButton *button5; IBOutlet UIButton *button6; IBOutlet UIButton *button7; IBOutlet UIButton *button8; IBOutlet UIButton *button9; IBOutlet UIButton *button10; IBOutlet UIButton *button11; IBOutlet UIButton *button12; IBOutlet UIButton *button13; IBOutlet UIButton *button14; IBOutlet UIButton *button15; IBOutlet UIButton *button16; IBOutlet UIImageView *flash1; IBOutlet UIImageView *flash2; IBOutlet UIImageView *flash3; IBOutlet UIImageView *flash4; IBOutlet UIImageView *flash5; IBOutlet UIImageView *flash6; IBOutlet UIImageView *flash7; IBOutlet UIImageView *flash8; IBOutlet UIImageView *flash9; IBOutlet UIImageView *flash10; IBOutlet UIImageView *flash11; IBOutlet UIImageView *flash12; IBOutlet UIImageView *flash13; IBOutlet UIImageView *flash14; IBOutlet UIImageView *flash15; IBOutlet UIImageView *flash16; Boolean animation; int random; int stick; AVAudioPlayer *click; AVAudioPlayer *failsound; AVAudioPlayer *button_press; NSURL *buttonpress; NSURL *musicFile; NSURL *fail; NSURL *yay; } @property (strong) UIImageView *imageview; @property (strong) IBOutlet UIImageView *background; @property (nonatomic) IBOutlet UIButton *scanticket; @property (nonatomic) IBOutlet UIButton *displaypic; @property (nonatomic) IBOutlet UIButton *changecov; @property (nonatomic) IBOutlet UIBarButtonItem *leaderboard; @property (strong) IBOutlet UIImageView *displaypicture; @property (strong) NSString* IsItComplete; @property (nonatomic) int completecount; @property (nonatomic) int stickercount; @property (nonatomic) BOOL* toggleleaderboard; @property (strong, nonatomic) NSString *name; @property (strong) NSString *totaltickets; @property (strong) NSMutableArray *stickerarray; @property (strong) NSMutableArray *touchDownStickers; @property (strong) IBOutlet UIButton *redeem; @property (strong, nonatomic) IBOutlet UILabel *childname; @property (nonatomic) IBOutlet UILabel *tickets; @property (weak, nonatomic) IBOutlet UIButton *message; //leaderboard objects @property (nonatomic) IBOutlet UILabel *nexttarget; @property (nonatomic) IBOutlet UILabel *behindyou; @property (nonatomic, strong) IBOutlet UILabel *stickerlabel; @property (nonatomic, strong) IBOutlet UILabel *completelabel; @property (weak, nonatomic) IBOutlet ChildrenDetailControl *Hub; //Core sticker collection objects @property (nonatomic) IBOutlet UIButton *button1; @property (nonatomic) IBOutlet UIButton *button2; @property (nonatomic) IBOutlet UIButton *button3; @property (nonatomic) IBOutlet UIButton *button4; @property (nonatomic) IBOutlet UIButton *button5; @property (nonatomic) IBOutlet UIButton *button6; @property (nonatomic) IBOutlet UIButton *button7; @property (nonatomic) IBOutlet UIButton *button8; @property (nonatomic) IBOutlet UIButton *button9; @property (nonatomic) IBOutlet UIButton *button10; @property (nonatomic) IBOutlet UIButton *button11; @property (nonatomic) IBOutlet UIButton *button12; @property (nonatomic) IBOutlet UIButton *button13; @property (nonatomic) IBOutlet UIButton *button14; @property (nonatomic) IBOutlet UIButton *button15; @property (nonatomic) IBOutlet UIButton *button16; @property (nonatomic) IBOutlet UIImageView *flash1; @property (nonatomic) IBOutlet UIImageView *flash2; @property (nonatomic) IBOutlet UIImageView *flash3; @property (nonatomic) IBOutlet UIImageView *flash4; @property (nonatomic) IBOutlet UIImageView *flash5; @property (nonatomic) IBOutlet UIImageView *flash6; @property (nonatomic) IBOutlet UIImageView *flash7; @property (nonatomic) IBOutlet UIImageView *flash8; @property (nonatomic) IBOutlet UIImageView *flash9; @property (nonatomic) IBOutlet UIImageView *flash10; @property (nonatomic) IBOutlet UIImageView *flash11; @property (nonatomic) IBOutlet UIImageView *flash12; @property (nonatomic) IBOutlet UIImageView *flash13; @property (nonatomic) IBOutlet UIImageView *flash14; @property (nonatomic) IBOutlet UIImageView *flash15; @property (nonatomic) IBOutlet UIImageView *flash16; @property (nonatomic) Boolean animation; @property (nonatomic) int random; @property (nonatomic) int randomstick; @property (nonatomic) int stick; @property (nonatomic) id pickerDelegate; -(IBAction)UnlockSticker: (UIButton*) stickerbutton; -(IBAction)touchDownSticker: (id) sender: (UIButton*) stickers; -(IBAction)touchUpSticker: (id) sender: (UIButton*) stickers1; - (IBAction)hideShowMessage:(UIButton*)sender; -(void)updateMessage:(NSString*)message; -(IBAction)switchViews:(id)sender; -(IBAction)changedp:(id)sender; -(IBAction)leaderboard:(UIBarButtonItem*)leaderboard; -(NSString *) filePath; -(void)UpdatecurrentTickets; -(void)openDB; -(void)setMessageButton; @end Filename : TableViewStory/ChildrenTableViewCell.h // // ChildrenTableViewCell.h // TableViewStory // // Created by Oliver Jarrett on 28/10/2012. // Copyright (c) 2012 Oliver Jarrett. All rights reserved. // #import @interface ChildrenTableViewCell : UITableViewCell @property (nonatomic, strong) IBOutlet UILabel *childname; @end Filename : TableViewStory/QRCodeAddView.h // // QRCodeAddView.h // TableViewStory // // Created by Oliver Jarrett on 06/03/2013. // Copyright (c) 2013 Oliver Jarrett. All rights reserved. // #import #import "sqlite3.h" @interface QRCodeAddView : UIViewController { sqlite3 *qrdb; } @property (weak, nonatomic) IBOutlet UITextField *nameField; @property (weak, nonatomic) IBOutlet UITextField *messageField; @property (weak, nonatomic) IBOutlet UINavigationBar *bar; @property (weak, nonatomic) IBOutlet UILabel *errorLabel; @property (weak, nonatomic) IBOutlet UISegmentedControl *valueSegment; -(IBAction)hypertext:(id)sender; -(IBAction)Done:(id)sender; -(IBAction)Cancel:(id)sender; -(void)manageMode; -(void)openDB; @end Filename : TableViewStory/QRCodeTableCell.h // // QRCodeTableCell.h // TableViewStory // // Created by Oliver Jarrett on 05/03/2013. // Copyright (c) 2013 Oliver Jarrett. All rights reserved. // #import #import "sqlite3.h" @interface QRCodeTableCell : UITableViewCell { sqlite3 *qrdb; } @property (nonatomic, strong) IBOutlet UILabel *title; @property (nonatomic, strong) IBOutlet UILabel *description; @property (nonatomic, strong) IBOutlet UILabel *lastused; @property (nonatomic, strong) IBOutlet UILabel *count; @property (nonatomic, strong) IBOutlet UIStepper *increment; - (IBAction)Increment:(id)sender; @end Filename : TableViewStory/QRCodeTableView.h // // QRCodeTableView.h // TableViewStory // // Created by Oliver Jarrett on 05/03/2013. // Copyright (c) 2013 Oliver Jarrett. All rights reserved. // #import #import "sqlite3.h" @interface QRCodeTableView : UITableViewController { sqlite3 *qrdb; } -(NSString *) filePath; -(void)openDB; -(IBAction)editting:(id)sender; @end Filename : TableViewStory/TableSplitViewController.h // // TableSplitViewController.h // TableViewStory // // Created by Oliver Jarrett on 30/01/2013. // Copyright (c) 2013 Oliver Jarrett. All rights reserved. // #import #import "ChildrenTableViewController.h" #import "sqlite3.h" @interface TableSplitViewController : UIViewController { ChildrenTableViewController *firstController; sqlite3 *Childdb; sqlite3 *qrdb; IBOutlet UITableView *firstTable; IBOutlet UITableViewCell *tablecell; NSNumber *IsAChild; } @property (nonatomic, strong) NSString *name; @property (nonatomic, strong) IBOutlet UIBarButtonItem *Teacherbutton; @property (nonatomic, strong) IBOutlet UIBarButtonItem *Children; @property (nonatomic, strong) IBOutlet UITextField *passwordfield; @property (nonatomic, strong) NSMutableArray *listofnames; @property (nonatomic, strong) IBOutlet UIButton *submit; @property (nonatomic, strong) IBOutlet UILabel *childnamelabel; @property (nonatomic, strong) IBOutlet UILabel *teachernamelabel; @property (nonatomic) IBOutlet UITableViewCell *tablecell; @property (nonatomic) IBOutlet UIButton *LogInButton; @property (nonatomic,weak) NSNumber *IsAChild; @property (nonatomic, strong) UISwipeGestureRecognizer *swipeleft; @property (nonatomic, strong) UISwipeGestureRecognizer *swiperight; @property (nonatomic, strong) IBOutlet UIImageView *displaypicture; -(IBAction)PressedTeacherButton: (UIBarButtonItem*) Teacherbutton; -(IBAction)PressedLogInButton:(UIButton*)LogInButton; -(NSString *) filePath; -(void)openDB; -(void) createTable: (NSString*) tableName withField1:(NSString*)field1 withField2:(NSString*)field2 withField3:(NSString*)field3 withField4:(NSString*)field4 withField5:(NSString*)field5 withField6:(NSString*)field6 withField7:(NSString*)field7 withField8:(NSString*)field8 withField9:(NSString*)field9 withField10:(NSString*)field10 withField11:(NSString*)field11 withField12:(NSString*)field12 withField13:(NSString*)field13 withField14:(NSString*)field14 withField15:(NSString*)field15; -(void) createQRTable: (NSString*)tableName withField1:(NSString*)field1 withField2:(NSString*)field2 withField3:(NSString*)field3 withField4:(NSString*)field4 withField5:(NSString*)field5 withField6:(NSString*)field6; @end Filename : TableViewStory/TableViewStoryAppDelegate.h // // TableViewStoryAppDelegate.h // TableViewStory // // Created by Oliver Jarrett on 28/10/2012. // Copyright (c) 2012 Oliver Jarrett. All rights reserved. // #import #import "ZBarSDK.h" @interface TableViewStoryAppDelegate : UIResponder{ } @property (strong, nonatomic) UIWindow *window; //@property (nonatomic, strong) IBOutlet UIWindow *qrwindow; //property of embedded reader //@property (nonatomic, strong) IBOutlet ZBarReaderViewController *viewController;//property of embedded reader @end Filename : TableViewStory/TeacherAddChildController.h // // TeacherAddChildController.h // TableViewStory // // Created by Oliver Jarrett on 10/02/2013. // Copyright (c) 2013 Oliver Jarrett. All rights reserved. // #import #import "sqlite3.h" @protocol UpdateTable @required - (void) UpdateTable:(NSString *)sender; @end @interface TeacherAddChildController : UIViewController { sqlite3 *Childdb; id delegate1; } @property (strong, nonatomic) IBOutlet UITextField *Name; @property (strong, nonatomic) IBOutlet UITextField *Password; @property (strong, nonatomic) IBOutlet UISegmentedControl *House; @property (weak, nonatomic) IBOutlet UILabel *errorLabel; -(NSString *) filePath; -(void)openDB; @property (weak) id delegate1; -(IBAction)saveEntry:(id)sender; -(IBAction)cancel:(id)sender; @end Filename : TableViewStory/TeacherEditSettings.h // // TeacherEditSettings.h // TableViewStory // // Created by Oliver Jarrett on 28/03/2013. // Copyright (c) 2013 Oliver Jarrett. All rights reserved. // #import @interface TeacherEditSettings : UIViewController @property (weak, nonatomic) IBOutlet UITextField *nameField; @property (weak, nonatomic) IBOutlet UITextField *passwordField; @property (weak) NSUserDefaults *prefs; - (IBAction)Save:(id)sender; - (IBAction)Cancel:(id)sender; @end Filename : TableViewStory/TeacherSplitTableCell.h // // TeacherSplitTableCell.h // TableViewStory // // Created by Oliver Jarrett on 07/02/2013. // Copyright (c) 2013 Oliver Jarrett. All rights reserved. // #import @interface TeacherSplitTableCell : UITableViewCell @property (nonatomic, strong) IBOutlet UILabel *childname; @property (nonatomic, strong) IBOutlet UILabel *totaltickets; @property (nonatomic, strong) IBOutlet UIProgressView *progress; @property (nonatomic) IBOutlet UILabel *complete; @end Filename : TableViewStory/TeacherSplitViewController.h // // TeacherSplitViewController.h // TableViewStory // // Created by Oliver Jarrett on 06/02/2013. // Copyright (c) 2013 Oliver Jarrett. All rights reserved. // #import #import "ChildrenTableViewController.h" #import "TeacherSplitTableController.h" #import "QRReader.h" #import "TeacherAddChildController.h" #import "sqlite3.h" @interface TeacherSplitViewController : UIViewController { TeacherSplitTableController *firstController; sqlite3 *Childdb; // IBOutlet UITableView *firstTable; } @property (strong, nonatomic) IBOutlet UITableView *firstTable; @property (nonatomic) BOOL *IsitQRCodeView; - (IBAction)editSettings:(id)sender; -(IBAction)edit:(id)sender; -(IBAction)tester: (UIButton*) tester; - (IBAction)ManageTickets:(id)sender; -(NSString *) filePath; -(void)openDB; @end Filename : TableViewStory/updateTicketLabel.h // // updateTicketLabel.h // TableViewStory // // Created by Oliver Jarrett on 23/11/2012. // Copyright (c) 2012 Oliver Jarrett. All rights reserved. // #import @protocol updateTicketLabel @required - (void) setTicketLabel:(NSString *)sender; @end @end