From 30d48ecfeac942473a4b08de2ac37816793984b0 Mon Sep 17 00:00:00 2001 From: Eddie Ehlin Date: Wed, 30 Jan 2013 22:26:41 +0100 Subject: Implemented support for adding and removing thresholds. --- .../UserInterfaceState.xcuserstate | Bin 44255 -> 43058 bytes .../xcdebugger/Breakpoints.xcbkptlist | 32 +++- iBean/iBean/AppDelegate+Storage.h | 2 + iBean/iBean/AppDelegate+Storage.m | 17 ++ iBean/iBean/BeanCollection+Interface.m | 3 +- iBean/iBean/Configuration+Interface.h | 4 + iBean/iBean/Configuration+Interface.m | 42 +++++ iBean/iBean/SettingsViewController.m | 10 ++ iBean/iBean/ThresholdCell.m | 14 +- iBean/iBean/ThresholdListViewController.h | 9 ++ iBean/iBean/ThresholdListViewController.m | 174 ++++++++++++++------- iBean/iBean/ThresholdViewController.h | 17 +- iBean/iBean/ThresholdViewController.m | 83 ++++++++++ iBean/iBean/iPhoneStoryboard.storyboard | 61 ++++++-- 14 files changed, 399 insertions(+), 69 deletions(-) diff --git a/iBean/iBean.xcodeproj/project.xcworkspace/xcuserdata/eddiex.xcuserdatad/UserInterfaceState.xcuserstate b/iBean/iBean.xcodeproj/project.xcworkspace/xcuserdata/eddiex.xcuserdatad/UserInterfaceState.xcuserstate index 7b3eccf..673cad7 100644 Binary files a/iBean/iBean.xcodeproj/project.xcworkspace/xcuserdata/eddiex.xcuserdatad/UserInterfaceState.xcuserstate and b/iBean/iBean.xcodeproj/project.xcworkspace/xcuserdata/eddiex.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/iBean/iBean.xcodeproj/xcuserdata/eddiex.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist b/iBean/iBean.xcodeproj/xcuserdata/eddiex.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist index 1563c41..d07f366 100644 --- a/iBean/iBean.xcodeproj/xcuserdata/eddiex.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist +++ b/iBean/iBean.xcodeproj/xcuserdata/eddiex.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist @@ -34,13 +34,39 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "iBean/AppDelegate+Storage.m" - timestampString = "380990077.537405" + timestampString = "381268321.748787" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "271" - endingLineNumber = "271" + startingLineNumber = "288" + endingLineNumber = "288" landmarkName = "-createTimer::::" landmarkType = "5"> + + + + diff --git a/iBean/iBean/AppDelegate+Storage.h b/iBean/iBean/AppDelegate+Storage.h index 44c4a0f..f668396 100644 --- a/iBean/iBean/AppDelegate+Storage.h +++ b/iBean/iBean/AppDelegate+Storage.h @@ -10,6 +10,7 @@ @class Configuration; @class BeanCollection; @class Bean; +@class Threshold; /* Main purpose of this category is to have all storage (core data) related @@ -35,6 +36,7 @@ //Thresholds methods - (void) processThresholds; +- (Threshold*) createThreshold; diff --git a/iBean/iBean/AppDelegate+Storage.m b/iBean/iBean/AppDelegate+Storage.m index fc911f6..fe62969 100644 --- a/iBean/iBean/AppDelegate+Storage.m +++ b/iBean/iBean/AppDelegate+Storage.m @@ -160,6 +160,23 @@ //Find out how to make the list of thresholds sorted on the value. } +- (Threshold*) createThreshold +{ + Threshold *t = nil; + + if (self.managedObjectContext != nil) + { + t = [NSEntityDescription insertNewObjectForEntityForName:@"Threshold" inManagedObjectContext:self.managedObjectContext]; + + //Set default values + if (t != nil) + { + //TODO: Set default values here... + } + } + return t; +} + #pragma mark - Instant extraction related methods (using Configuraiton) - (NSError*)setInstantExtractionTimer:(NSNumber *)extractionTimer { diff --git a/iBean/iBean/BeanCollection+Interface.m b/iBean/iBean/BeanCollection+Interface.m index e01e25e..efc35c6 100644 --- a/iBean/iBean/BeanCollection+Interface.m +++ b/iBean/iBean/BeanCollection+Interface.m @@ -34,7 +34,8 @@ NSLog(@"BeanCollection+Interface - removeBeansObjectAtIndex: Index out of range!"); } -- (void)replaceBeansAtIndexes:(NSIndexSet *)beanIndexes withBeans:(NSArray *)beans { +- (void)replaceBeansAtIndexes:(NSIndexSet *)beanIndexes withBeans:(NSArray *)beans +{ /* [self willChange:NSKeyValueChangeReplacement valuesAtIndexes:indexes forKey:@"beans"]; NSMutableOrderedSet *tmpOrderedSet = [NSMutableOrderedSet orderedSetWithOrderedSet:[self mutableOrderedSetValueForKey:@"beans"]]; diff --git a/iBean/iBean/Configuration+Interface.h b/iBean/iBean/Configuration+Interface.h index d2660b7..6e66cfe 100644 --- a/iBean/iBean/Configuration+Interface.h +++ b/iBean/iBean/Configuration+Interface.h @@ -10,4 +10,8 @@ @interface Configuration (Interface) +- (void) addThresholdsObject: (Threshold *)t; +- (void) removeObjectFromThresholdsAtIndex:(NSUInteger)thresholdIndex; +- (void)replaceThresholdsAtIndexes:(NSIndexSet *)thresholdIndexes withThresholds:(NSArray *)thresholds; + @end diff --git a/iBean/iBean/Configuration+Interface.m b/iBean/iBean/Configuration+Interface.m index 549997e..230f529 100644 --- a/iBean/iBean/Configuration+Interface.m +++ b/iBean/iBean/Configuration+Interface.m @@ -10,4 +10,46 @@ @implementation Configuration (Interface) +- (void) addThresholdsObject:(Threshold *)t +{ + NSMutableOrderedSet *tmpSet = [self mutableOrderedSetValueForKey:@"thresholds"]; + [tmpSet addObject:t]; +} + +- (void) removeObjectFromThresholdsAtIndex:(NSUInteger)thresholdIndex +{ + /* + NSIndexSet* indexes = [NSIndexSet indexSetWithIndex:idx]; + [self willChange:NSKeyValueChangeRemoval valuesAtIndexes:indexes forKey:@"beans"]; + NSMutableOrderedSet *tmpOrderedSet = [NSMutableOrderedSet orderedSetWithOrderedSet:[self mutableOrderedSetValueForKey:@"beans"]]; + [tmpOrderedSet removeObjectAtIndex:idx]; + [self setPrimitiveValue:tmpOrderedSet forKey:@"beans"]; + [self didChange:NSKeyValueChangeRemoval valuesAtIndexes:indexes forKey:@"beans"]; + */ + + NSMutableOrderedSet *tmpSet = [self mutableOrderedSetValueForKey:@"thresholds"]; + if (thresholdIndex >= 0 && thresholdIndex < tmpSet.count) + [tmpSet removeObjectAtIndex:thresholdIndex]; + else + NSLog(@"Configuration+Interface - removeObjectFromThresholdsAtIndex: Index out of range!"); +} + +- (void)replaceThresholdsAtIndexes:(NSIndexSet *)thresholdsIndexes withBeans:(NSArray *)thresholds +{ + /* + [self willChange:NSKeyValueChangeReplacement valuesAtIndexes:indexes forKey:@"beans"]; + NSMutableOrderedSet *tmpOrderedSet = [NSMutableOrderedSet orderedSetWithOrderedSet:[self mutableOrderedSetValueForKey:@"beans"]]; + [tmpOrderedSet replaceObjectsAtIndexes:indexes withObjects:values]; + [self setPrimitiveValue:tmpOrderedSet forKey:@"beans"]; + [self didChange:NSKeyValueChangeReplacement valuesAtIndexes:indexes forKey:@"beans"]; + */ + + if (thresholds.count > 0) + { + NSMutableOrderedSet *tmpSet = [self mutableOrderedSetValueForKey:@"thresholds"]; + [tmpSet replaceObjectsAtIndexes:thresholdsIndexes withObjects:thresholds]; + } + +} + @end diff --git a/iBean/iBean/SettingsViewController.m b/iBean/iBean/SettingsViewController.m index cce498f..242bee1 100644 --- a/iBean/iBean/SettingsViewController.m +++ b/iBean/iBean/SettingsViewController.m @@ -9,6 +9,7 @@ #import "SettingsViewController.h" #import "Configuration+Interface.h" #import "AppDelegate+Storage.h" +#import "ThresholdListViewController.h" @interface SettingsViewController () @@ -48,6 +49,15 @@ // Dispose of any resources that can be recreated. } +- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender +{ + if ([segue.identifier isEqualToString:@"SettingsThresholdSegue"]) + { + ThresholdListViewController *thresholdListViewController = segue.destinationViewController; + [thresholdListViewController initWithConfiguration:self.configuration]; + } +} + /***************************************************** Utility methods *****************************************************/ diff --git a/iBean/iBean/ThresholdCell.m b/iBean/iBean/ThresholdCell.m index b18bd57..bc89b4b 100644 --- a/iBean/iBean/ThresholdCell.m +++ b/iBean/iBean/ThresholdCell.m @@ -8,6 +8,7 @@ #import "ThresholdCell.h" #import "Threshold.h" +#import "AppDelegate+Storage.h" @implementation ThresholdCell @@ -53,7 +54,18 @@ if (self.threshold != nil) { self.threshold.enabled = [NSNumber numberWithBool:self.enabledSwitch.on]; -#warning TODO - Trigger save!? + NSError* error = [(AppDelegate*) [[UIApplication sharedApplication] delegate] save]; + if (error != nil) + { + //Rollback + [(AppDelegate*) [[UIApplication sharedApplication] delegate] rollback]; + + UIAlertView *switchChangedSaveAlert = [[UIAlertView alloc] initWithTitle:@"Save error!" message:@"iBean was unable to save threshold state!\nPlease try again." delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil]; + [switchChangedSaveAlert show]; + + #warning TODO - Make sure that rollback resets the value back to previous one!!!!! + self.enabledSwitch.on = [self.threshold.enabled boolValue]; + } } } diff --git a/iBean/iBean/ThresholdListViewController.h b/iBean/iBean/ThresholdListViewController.h index eb909d7..1ec6266 100644 --- a/iBean/iBean/ThresholdListViewController.h +++ b/iBean/iBean/ThresholdListViewController.h @@ -7,14 +7,23 @@ // #import +@class Configuration; @interface ThresholdListViewController : UIViewController +@property (nonatomic, strong) Configuration* configuration; +@property (nonatomic, strong) UIBarButtonItem *thresholdListEditDoneButton; + /* Utility methods */ - (void) initViewController; +- (void) initWithConfiguration: (Configuration*) configuration; /* UI Outlets */ +@property (weak, nonatomic) IBOutlet UITableView *thresholdListTableView; +@property (weak, nonatomic) IBOutlet UIToolbar *thresholdListBottomToolbar; +@property (strong, nonatomic) IBOutlet UIBarButtonItem *thresholdListEditButton; /* UI Actions */ +- (IBAction)toggleEditMode:(id)sender; @end diff --git a/iBean/iBean/ThresholdListViewController.m b/iBean/iBean/ThresholdListViewController.m index d6ce20e..57db263 100644 --- a/iBean/iBean/ThresholdListViewController.m +++ b/iBean/iBean/ThresholdListViewController.m @@ -7,6 +7,10 @@ // #import "ThresholdListViewController.h" +#import "ThresholdViewController.h" +#import "Configuration+Interface.h" +#import "ThresholdCell.h" +#import "AppDelegate+Storage.h" @interface ThresholdListViewController () @@ -29,21 +33,65 @@ // Do any additional setup after loading the view. } +- (void) viewWillAppear:(BOOL)animated +{ + [super viewWillAppear:animated]; + [self initViewController]; +} + - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } +- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender +{ + if ([segue.identifier isEqualToString:@"ThresholdsAddNewThresholdSegue"]) + { + ThresholdViewController* thresholdViewController = segue.destinationViewController; + [thresholdViewController initWithConfigurationAndThresholdIndex:self.configuration : -1]; + } + else if ([segue.identifier isEqualToString:@"ThresholdsEditThresholdSegue"]) + { + ThresholdViewController* thresholdViewController = segue.destinationViewController; + [thresholdViewController initWithConfigurationAndThresholdIndex:self.configuration :self.thresholdListTableView.indexPathForSelectedRow.row]; + } +} + /***************************************************** Utility methods *****************************************************/ +- (void) initViewController +{ + NSLog(@"ThresholdListViewController - initViewController"); + [self.thresholdListTableView reloadData]; + self.thresholdListEditDoneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(toggleEditMode:)]; +} +- (void) initWithConfiguration:(Configuration *)configuration +{ + self.configuration = configuration; +} /***************************************************** UI Actions *****************************************************/ - +#pragma mark - IBActions +- (void) toggleEditMode:(id)sender +{ + NSMutableArray *bottomToolbarItems = [NSMutableArray arrayWithArray:self.thresholdListBottomToolbar.items]; + if (self.thresholdListTableView.editing) + { + [bottomToolbarItems replaceObjectAtIndex:0 withObject:self.thresholdListEditButton]; + } + else + { + [bottomToolbarItems replaceObjectAtIndex:0 withObject:self.thresholdListEditDoneButton]; + } + [self.thresholdListTableView setEditing:!self.thresholdListTableView.editing animated:YES]; + [self.thresholdListBottomToolbar setItems:bottomToolbarItems animated:YES]; +} /***************************************************** Delegates @@ -52,78 +100,98 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { -#warning Potentially incomplete method implementation. // Return the number of sections. - return 0; + return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { -#warning Incomplete method implementation. // Return the number of rows in the section. - return 0; + return self.configuration.thresholds.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"ThresholdCell"; - UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; + ThresholdCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; // Configure the cell... + [cell initWithThresholdEntity:[self.configuration.thresholds objectAtIndex:indexPath.row]]; 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; - } - */ - #pragma mark - Table view delegate -- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +// Override to support conditional editing of the table view. +- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { - // Navigation logic may go here. Create and push another view controller. - /* - <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil]; - // ... - // Pass the selected object to the new view controller. - [self.navigationController pushViewController:detailViewController animated:YES]; - */ + // Return NO if you do not want the specified item to be editable (we want to be able to REMOVE though). + 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 + if (self.configuration != nil) + { + [self.configuration removeObjectFromThresholdsAtIndex: indexPath.row]; + } + [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; + + //Commit change! + if ([(AppDelegate*) [[UIApplication sharedApplication] delegate] save] != nil) + { + UIAlertView *deleteRowAlert = [[UIAlertView alloc] initWithTitle:@"Configuration error!" message:@"iBean was unable to delete threshold!\nPlease try again." delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil]; + [deleteRowAlert show]; + + //Rollback and reload table view + [(AppDelegate*) [[UIApplication sharedApplication] delegate] rollback]; + [self.thresholdListTableView reloadData]; + } + + } + 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 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; +} + +// Override to support rearranging the table view. +//http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/tableview_iphone/ManageReorderRow/ManageReorderRow.html +- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath +{ + if (self.configuration != nil && fromIndexPath.row != toIndexPath.row) + { + NSLog(@"From: %d, To: %d", fromIndexPath.row, toIndexPath.row); + if (toIndexPath.row < (self.configuration.thresholds.count - 1)) + { + NSMutableIndexSet *thresholdIndexes = [NSMutableIndexSet indexSetWithIndex:fromIndexPath.row]; + [thresholdIndexes addIndex:toIndexPath.row]; + NSArray *thresholds = [NSArray arrayWithObjects:[self.configuration.thresholds objectAtIndex:fromIndexPath.row], [self.configuration.thresholds objectAtIndex:toIndexPath.row], nil]; + [self.configuration replaceThresholdsAtIndexes:thresholdIndexes withThresholds:thresholds]; + + //Commit change + if ([(AppDelegate*) [[UIApplication sharedApplication] delegate] save] != nil) + { + UIAlertView *deleteRowAlert = [[UIAlertView alloc] initWithTitle:@"Configuration error!" message:@"iBean was unable to move threshold!\nPlease try again." delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil]; + [deleteRowAlert show]; + + //Rollback and reload table view + [(AppDelegate*) [[UIApplication sharedApplication] delegate] rollback]; + [self.thresholdListTableView reloadData]; + } + } + } +} + + @end diff --git a/iBean/iBean/ThresholdViewController.h b/iBean/iBean/ThresholdViewController.h index dc63752..29d4874 100644 --- a/iBean/iBean/ThresholdViewController.h +++ b/iBean/iBean/ThresholdViewController.h @@ -7,14 +7,29 @@ // #import +@class Threshold; +@class Configuration; -@interface ThresholdViewController : UITableViewController +@interface ThresholdViewController : UITableViewController + +@property (nonatomic, assign) NSInteger thresholdObjectIndex; +@property (nonatomic, strong) Configuration* configuration; /* Utility methods */ - (void) initViewController; +- (void) initWithConfigurationAndThresholdIndex: (Configuration*) configuration: (NSInteger) thresholdIndex; /* UI Outlets */ +@property (weak, nonatomic) IBOutlet UITextField *thresholdNameTextField; +@property (weak, nonatomic) IBOutlet UILabel *thresholdValueLabel; +@property (weak, nonatomic) IBOutlet UIStepper *thresholdValueStepper; +@property (weak, nonatomic) IBOutlet UISwitch *thresholdEnabledSwitch; /* UI Actions */ +- (IBAction)valueStepperChanged:(id)sender; +- (IBAction)commitThreshold:(id)sender; + +/* UITextFieldDelegate */ +- (BOOL)textFieldShouldReturn:(UITextField *)textField; @end diff --git a/iBean/iBean/ThresholdViewController.m b/iBean/iBean/ThresholdViewController.m index 1769dfe..2e01373 100644 --- a/iBean/iBean/ThresholdViewController.m +++ b/iBean/iBean/ThresholdViewController.m @@ -6,7 +6,10 @@ // Copyright (c) 2013 Eddie Ehlin. All rights reserved. // +#import "AppDelegate+Storage.h" #import "ThresholdViewController.h" +#import "Threshold.h" +#import "Configuration+Interface.h" @interface ThresholdViewController () @@ -34,6 +37,12 @@ // self.navigationItem.rightBarButtonItem = self.editButtonItem; } +- (void) viewWillAppear:(BOOL)animated +{ + [super viewWillAppear:animated]; + [self initViewController]; +} + - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; @@ -43,15 +52,89 @@ /***************************************************** Utility methods *****************************************************/ +- (void) initViewController +{ + NSLog(@"ThresholdViewController - initViewController"); + + if (self.thresholdObjectIndex >= 0 && self.thresholdObjectIndex <= self.configuration.thresholds.count) + { + //We are editing an existing threshold! + Threshold *tmpThreshold = [self.configuration.thresholds objectAtIndex:self.thresholdObjectIndex]; + self.thresholdNameTextField.text = tmpThreshold.name; + self.thresholdEnabledSwitch.on = [tmpThreshold.enabled boolValue]; + self.thresholdValueStepper.value = [tmpThreshold.value doubleValue]; + [self valueStepperChanged:self]; + } + +} +- (void) initWithConfigurationAndThresholdIndex: (Configuration*) configuration: (NSInteger) thresholdIndex; +{ + self.configuration = configuration; + self.thresholdObjectIndex = thresholdIndex; +} /***************************************************** UI Actions *****************************************************/ +- (void) valueStepperChanged:(id)sender +{ + self.thresholdValueLabel.text = [[NSNumber numberWithDouble:self.thresholdValueStepper.value] stringValue]; +} + +- (void) commitThreshold:(id)sender +{ + Threshold* threshold = nil; + NSError* commitError = nil; + if (self.thresholdObjectIndex >= 0) + { + threshold = [self.configuration.thresholds objectAtIndex:self.thresholdObjectIndex]; + } + else + { + threshold = [(AppDelegate*) [[UIApplication sharedApplication] delegate] createThreshold]; + [self.configuration addThresholdsObject:threshold]; + } + + if (threshold != nil) + { + threshold.name = self.thresholdNameTextField.text; + threshold.value = [NSNumber numberWithDouble:self.thresholdValueStepper.value]; + threshold.enabled = [NSNumber numberWithBool:self.thresholdEnabledSwitch.on]; + + //Commit changes and save succeeds then return to list of thresholds. + commitError = [(AppDelegate*) [[UIApplication sharedApplication] delegate] save]; + } + + if (threshold == nil || commitError != nil) + { + //Rollback & present error! + [(AppDelegate*) [[UIApplication sharedApplication] delegate] rollback]; + + UIAlertView *commitThresholdAlert = [[UIAlertView alloc] initWithTitle:@"Save error!" message:@"iBean was unable to save threshold!\nPlease try again." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; + [commitThresholdAlert show]; + } + else + { + [self.navigationController popViewControllerAnimated:YES]; + } +} /***************************************************** Delegates *****************************************************/ +//Purpose: When "return" is pressed the keyboard will go away and "change" event will be triggered. +- (BOOL)textFieldShouldReturn:(UITextField *)textField +{ + //Return key makes the keyboard go away. + if (textField == self.thresholdNameTextField) + { + [textField resignFirstResponder]; + return YES; + } + + return NO; +} @end diff --git a/iBean/iBean/iPhoneStoryboard.storyboard b/iBean/iBean/iPhoneStoryboard.storyboard index 683bc9f..cec0cd1 100644 --- a/iBean/iBean/iPhoneStoryboard.storyboard +++ b/iBean/iBean/iPhoneStoryboard.storyboard @@ -286,7 +286,7 @@ - + @@ -371,7 +371,11 @@ - + + + + + @@ -393,6 +397,11 @@ + + + + + @@ -416,13 +425,16 @@ - + - + + + + @@ -451,7 +463,7 @@ - - + + + + + + + + + + + @@ -1013,7 +1039,7 @@ - + @@ -1287,6 +1313,7 @@ + @@ -1294,9 +1321,23 @@ + + + + + + + + + + + + + + @@ -1305,8 +1346,8 @@ - - + + \ No newline at end of file -- cgit v1.2.3