aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEddie Ehlin <eddiex@eddiex.se>2013-01-13 01:11:29 +0100
committerEddie Ehlin <eddiex@eddiex.se>2013-01-13 01:11:29 +0100
commit5ea77865b929a80e9f32f7d1304cdfbdaec819d5 (patch)
treed2fc1b4c6235abc4d9d773b56d6c3b2bd81e84af
parentc8549ce4b0f874a597f1f7edf820cd1dd1b1f9f0 (diff)
downloadiBean-5ea77865b929a80e9f32f7d1304cdfbdaec819d5.tar.gz
iBean-5ea77865b929a80e9f32f7d1304cdfbdaec819d5.zip
Minor code clean-up + cancellation dialog on BeanCollection.
-rw-r--r--iBean/iBean/BeanCollectionInfoViewController.h5
-rw-r--r--iBean/iBean/BeanCollectionInfoViewController.m70
-rw-r--r--iBean/iBean/BeanCollectionListViewController.m39
-rw-r--r--iBean/iBean/iPhoneStoryboard.storyboard9
4 files changed, 51 insertions, 72 deletions
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 <UIKit/UIKit.h>
@class BeanCollection;
-@interface BeanCollectionInfoViewController : UIViewController <UITextFieldDelegate, UITextViewDelegate>
+@interface BeanCollectionInfoViewController : UIViewController <UITextFieldDelegate, UITextViewDelegate, UIAlertViewDelegate>
@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 @@
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" returnKeyType="done"/>
<connections>
- <action selector="beanCollectioNameChanged" destination="5Zc-ii-ZPi" eventType="editingDidEnd" id="djb-Vf-Hjd"/>
<outlet property="delegate" destination="5Zc-ii-ZPi" id="z1c-9h-NJ9"/>
</connections>
</textField>
@@ -238,7 +237,7 @@
<navigationItem key="navigationItem" title="Information (1/3)" id="znt-MK-XJf">
<barButtonItem key="leftBarButtonItem" systemItem="cancel" id="x9O-iQ-Nw6">
<connections>
- <segue destination="C1o-is-nML" kind="modal" id="roV-hD-UY6"/>
+ <action selector="cancelBeanCollection:" destination="5Zc-ii-ZPi" id="MRl-v0-o1G"/>
</connections>
</barButtonItem>
<barButtonItem key="rightBarButtonItem" title="Next" id="HeX-Kh-3ba">
@@ -252,6 +251,7 @@
<outlet property="beanCollectionNextButton" destination="HeX-Kh-3ba" id="HdC-M9-1cq"/>
<outlet property="beanCollectionNoteTextView" destination="JHg-Fk-IL0" id="48Y-nc-5uX"/>
<outlet property="beanCollectionScrollView" destination="gb9-GM-dee" id="jSv-s1-WgA"/>
+ <segue destination="C1o-is-nML" kind="modal" identifier="BeanCollectionInfoCancelSegue" modalTransitionStyle="crossDissolve" id="OPZ-Pj-2Dz"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="m7P-Kh-vW4" userLabel="First Responder" sceneMemberID="firstResponder"/>
@@ -481,7 +481,7 @@
<navigationItem key="navigationItem" title="Extraction (3/3)" id="rnS-KT-Ugg">
<barButtonItem key="rightBarButtonItem" systemItem="done" id="a0e-Mo-oEY">
<connections>
- <segue destination="C1o-is-nML" kind="modal" identifier="CommitBeanCollectionSegue" id="CyX-df-8ge"/>
+ <segue destination="C1o-is-nML" kind="modal" identifier="CommitBeanCollectionSegue" modalTransitionStyle="flipHorizontal" id="CyX-df-8ge"/>
</connections>
</barButtonItem>
</navigationItem>
@@ -660,8 +660,7 @@
<class className="BeanCollectionInfoViewController" superclassName="UIViewController">
<source key="sourceIdentifier" type="project" relativePath="./Classes/BeanCollectionInfoViewController.h"/>
<relationships>
- <relationship kind="action" name="beanCollectioNameChanged"/>
- <relationship kind="action" name="beanCollectionNoteChanged"/>
+ <relationship kind="action" name="cancelBeanCollection:"/>
<relationship kind="action" name="keyboardDisplayed:" candidateClass="NSNotification"/>
<relationship kind="action" name="keyboardHidden:" candidateClass="NSNotification"/>
<relationship kind="outlet" name="beanCollectionNameTextField" candidateClass="UITextField"/>