From bafbeea4d9400099c0a653cdabe6e41f7451995e Mon Sep 17 00:00:00 2001 From: Eddie Ehlin Date: Tue, 8 Jan 2013 22:58:56 +0100 Subject: Added "Done" button to the navigation bar when editing name or note for bean collection. --- .../UserInterfaceState.xcuserstate | Bin 30104 -> 30346 bytes iBean/iBean/BeanCollectionInfoViewController.h | 6 ++- iBean/iBean/BeanCollectionInfoViewController.m | 55 +++++++++++++-------- iBean/iBean/iPhoneStoryboard.storyboard | 2 + 4 files changed, 41 insertions(+), 22 deletions(-) (limited to 'iBean') 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 a31d1c9..f937bb9 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/BeanCollectionInfoViewController.h b/iBean/iBean/BeanCollectionInfoViewController.h index 815a7b1..bdb62fb 100644 --- a/iBean/iBean/BeanCollectionInfoViewController.h +++ b/iBean/iBean/BeanCollectionInfoViewController.h @@ -9,11 +9,12 @@ #import @class BeanCollection; -@interface BeanCollectionInfoViewController : UIViewController +@interface BeanCollectionInfoViewController : UIViewController @property (nonatomic, strong) BeanCollection *beanCollection; @property (nonatomic, assign) BOOL editMode; - +@property (strong, nonatomic) UIBarButtonItem *beanCollectionTextViewDoneButton; +@property (strong, nonatomic) UIBarButtonItem *beanCollectionTextFieldDoneButton; /* Utility methods */ - (void) initViewController; @@ -23,6 +24,7 @@ @property (weak, nonatomic) IBOutlet UITextField *beanCollectionNameTextField; @property (weak, nonatomic) IBOutlet UITextView *beanCollectionNoteTextView; @property (weak, nonatomic) IBOutlet UIScrollView *beanCollectionScrollView; +@property (strong, nonatomic) IBOutlet UIBarButtonItem *beanCollectionNextButton; /* UI Actions */ - (IBAction) beanCollectioNameChanged; diff --git a/iBean/iBean/BeanCollectionInfoViewController.m b/iBean/iBean/BeanCollectionInfoViewController.m index 39a6422..fd4e74a 100644 --- a/iBean/iBean/BeanCollectionInfoViewController.m +++ b/iBean/iBean/BeanCollectionInfoViewController.m @@ -71,28 +71,10 @@ } } -//Purpose: Hide keyboard when active control looses focus. -/* -- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event -{ - UITouch *touch = [[event allTouches] anyObject]; - if ([self.beanCollectionNoteTextView isFirstResponder] && [touch view] != self.beanCollectionNoteTextView) - { - //This will trigger textViewDidEndEditing which in turn will trigger beanCollectionNoteChanged - [self.beanCollectionNoteTextView resignFirstResponder]; - } - else if ([self.beanCollectionNameTextField isFirstResponder] && [touch view] != self.beanCollectionNameTextField) - { - [self.beanCollectionNameTextField resignFirstResponder]; - } - - [super touchesBegan:touches withEvent:event]; -} -*/ - /***************************************************** Utility methods *****************************************************/ +#pragma mark - Utility methods - (void) initViewController { NSLog(@"BeanCollectionInfoViewController - initViewController"); @@ -109,6 +91,10 @@ { NSLog(@"BeanCollectionInfoViewController - in add new state"); } + + //Allocate text view&field done button, which will replace Next button when needed. + self.beanCollectionTextViewDoneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self.beanCollectionNoteTextView action:@selector(resignFirstResponder)]; + self.beanCollectionTextFieldDoneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self.beanCollectionNameTextField action:@selector(resignFirstResponder)]; } - (void) initWithModeAndBeanCollection:(BOOL)editMode :(BeanCollection *)bc @@ -168,8 +154,25 @@ self.beanCollectionScrollView.scrollIndicatorInsets = contentInsets; } -/* UITextFieldDelegate */ +/***************************************************** + Delegates + *****************************************************/ #pragma mark - UITextFieldDelegate methods +- (void) textFieldDidBeginEditing:(UITextField *)textField +{ + if (textField == self.beanCollectionNameTextField) + { + self.navigationItem.rightBarButtonItem = self.beanCollectionTextFieldDoneButton; + } +} + +- (void) textFieldDidEndEditing:(UITextField *)textField +{ + if (textField == self.beanCollectionNameTextField) + { + self.navigationItem.rightBarButtonItem = self.beanCollectionNextButton; + } +} //Purpose: When "return" is pressed the keyboard will go away and "change" event will be triggered. - (BOOL)textFieldShouldReturn:(UITextField *)textField @@ -192,7 +195,19 @@ { //Update bean collection's note. [self beanCollectionNoteChanged]; + + //Change back to "Next" button + self.navigationItem.rightBarButtonItem = self.beanCollectionNextButton; } } +- (void) textViewDidBeginEditing:(UITextView *)textView +{ + if (textView == self.beanCollectionNoteTextView) + { + self.navigationItem.rightBarButtonItem = self.beanCollectionTextViewDoneButton; + } + +} + @end diff --git a/iBean/iBean/iPhoneStoryboard.storyboard b/iBean/iBean/iPhoneStoryboard.storyboard index 22197b1..c9fd722 100644 --- a/iBean/iBean/iPhoneStoryboard.storyboard +++ b/iBean/iBean/iPhoneStoryboard.storyboard @@ -246,6 +246,7 @@ + @@ -481,6 +482,7 @@ + -- cgit v1.2.3