From 5ea77865b929a80e9f32f7d1304cdfbdaec819d5 Mon Sep 17 00:00:00 2001 From: Eddie Ehlin Date: Sun, 13 Jan 2013 01:11:29 +0100 Subject: Minor code clean-up + cancellation dialog on BeanCollection. --- iBean/iBean/BeanCollectionInfoViewController.h | 5 +- iBean/iBean/BeanCollectionInfoViewController.m | 70 ++++++++++++++++---------- iBean/iBean/BeanCollectionListViewController.m | 39 +------------- iBean/iBean/iPhoneStoryboard.storyboard | 9 ++-- 4 files changed, 51 insertions(+), 72 deletions(-) (limited to 'iBean') diff --git a/iBean/iBean/BeanCollectionInfoViewController.h b/iBean/iBean/BeanCollectionInfoViewController.h index bdb62fb..3394d52 100644 --- a/iBean/iBean/BeanCollectionInfoViewController.h +++ b/iBean/iBean/BeanCollectionInfoViewController.h @@ -9,7 +9,7 @@ #import @class BeanCollection; -@interface BeanCollectionInfoViewController : UIViewController +@interface BeanCollectionInfoViewController : UIViewController @property (nonatomic, strong) BeanCollection *beanCollection; @property (nonatomic, assign) BOOL editMode; @@ -27,8 +27,7 @@ @property (strong, nonatomic) IBOutlet UIBarButtonItem *beanCollectionNextButton; /* UI Actions */ -- (IBAction) beanCollectioNameChanged; -- (IBAction) beanCollectionNoteChanged; +- (IBAction) cancelBeanCollection:(id)sender; - (IBAction) keyboardDisplayed:(NSNotification*)keyboardNotification; - (IBAction) keyboardHidden:(NSNotification*)keyboardNotification; diff --git a/iBean/iBean/BeanCollectionInfoViewController.m b/iBean/iBean/BeanCollectionInfoViewController.m index fd4e74a..68c6efb 100644 --- a/iBean/iBean/BeanCollectionInfoViewController.m +++ b/iBean/iBean/BeanCollectionInfoViewController.m @@ -8,6 +8,7 @@ #import "BeanCollectionInfoViewController.h" #import "BeanCollectionBeanListViewController.h" +#import "AppDelegate+Storage.h" #import "BeanCollection.h" @interface BeanCollectionInfoViewController () @@ -69,6 +70,27 @@ BeanCollectionBeanListViewController *beanListViewController = segue.destinationViewController; [beanListViewController initWithModeAndBeanCollection:self.editMode :self.beanCollection]; } + else if ([segue.identifier isEqualToString:@"BeanCollectionInfoCancelSegue"]) + { + //Wipe all changes! + [(AppDelegate*) [[UIApplication sharedApplication] delegate] rollback]; + } +} + +- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender +{ + + if ([identifier isEqualToString:@"BeanInfoBeanListSegue"]) + { + //Validate data (for now just tranfer UI data to the bean collection data structure) + if (self.beanCollection != nil) + { + self.beanCollection.name = self.beanCollectionNameTextField.text; + self.beanCollection.note = self.beanCollectionNoteTextView.text; + } + } + + return YES; } /***************************************************** @@ -81,10 +103,12 @@ if (self.editMode == YES) { - //Set values from bean collection structure. - self.beanCollectionNameTextField.text = self.beanCollection.name; - self.beanCollectionNoteTextView.text = self.beanCollection.note; - + if (self.beanCollection != nil) + { + //Set values from bean collection structure. + self.beanCollectionNameTextField.text = self.beanCollection.name; + self.beanCollectionNoteTextView.text = self.beanCollection.note; + } NSLog(@"BeanCollectionInfoViewController - in edit state"); } else @@ -107,24 +131,6 @@ UI Actions *****************************************************/ #pragma mark - IBActions - -- (void) beanCollectioNameChanged -{ - NSLog(@"BeanCollectionInfoViewController - beanCollectioNameChanged"); - if (self.beanCollection != nil) - { - self.beanCollection.name = self.beanCollectionNameTextField.text; - } -} -- (void) beanCollectionNoteChanged -{ - NSLog(@"BeanCollectionInfoViewController - beanCollectioNoteChanged"); - if (self.beanCollection != nil) - { - self.beanCollection.note = self.beanCollectionNoteTextView.text; - } -} - - (void) keyboardDisplayed:(NSNotification *)keyboardNotification { //Make sure that beanCollectionTextView is accessable even with keyboard visible. @@ -154,6 +160,11 @@ self.beanCollectionScrollView.scrollIndicatorInsets = contentInsets; } +- (void) cancelBeanCollection:(id)sender +{ + UIAlertView *confirmCancel = [[UIAlertView alloc] initWithTitle:@"Cancel?" message:@"Are you sure you want to cancel?\n(Data entered will be lost)" delegate:self cancelButtonTitle:@"Yes" otherButtonTitles:@"No", nil]; + [confirmCancel show]; +} /***************************************************** Delegates *****************************************************/ @@ -192,10 +203,7 @@ - (void)textViewDidEndEditing:(UITextView *)textView { if (textView == self.beanCollectionNoteTextView) - { - //Update bean collection's note. - [self beanCollectionNoteChanged]; - + { //Change back to "Next" button self.navigationItem.rightBarButtonItem = self.beanCollectionNextButton; } @@ -210,4 +218,14 @@ } +#pragma mark - UIAlertViewDelegate methods +- (void) alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex +{ + //User has confirmed cancellation? + if (buttonIndex == 0) + { + [self performSegueWithIdentifier:@"BeanCollectionInfoCancelSegue" sender:self]; + } +} + @end diff --git a/iBean/iBean/BeanCollectionListViewController.m b/iBean/iBean/BeanCollectionListViewController.m index 4432fe5..f466437 100644 --- a/iBean/iBean/BeanCollectionListViewController.m +++ b/iBean/iBean/BeanCollectionListViewController.m @@ -130,37 +130,7 @@ } } -/* -// 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 -#warning TODO: Remove this method, not needed since we are using storyboard based design? -/* -- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(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]; - -} -*/ - /***************************************************** Utility methods @@ -171,14 +141,7 @@ //Allocate edit's done button self.beanCollectionsListEditDoneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(toggleEditMode:)]; - - //Remove "new" bean collection if it is allocated - if (self.beanCollection != nil) - { - self.beanCollection = nil; - [(AppDelegate*) [[UIApplication sharedApplication] delegate] rollback]; - } - + //Load bean collections from core data storage self.beanCollections = [(AppDelegate*) [[UIApplication sharedApplication] delegate] getBeanCollections]; if (self.beanCollections != nil) diff --git a/iBean/iBean/iPhoneStoryboard.storyboard b/iBean/iBean/iPhoneStoryboard.storyboard index 153d02f..48e94df 100644 --- a/iBean/iBean/iPhoneStoryboard.storyboard +++ b/iBean/iBean/iPhoneStoryboard.storyboard @@ -184,7 +184,6 @@ - @@ -238,7 +237,7 @@ - + @@ -252,6 +251,7 @@ + @@ -481,7 +481,7 @@ - + @@ -660,8 +660,7 @@ - - + -- cgit v1.2.3