aboutsummaryrefslogtreecommitdiffstats
path: root/iBean
diff options
context:
space:
mode:
authorEddie Ehlin <eddiex@eddiex.se>2013-01-08 22:58:56 +0100
committerEddie Ehlin <eddiex@eddiex.se>2013-01-08 22:58:56 +0100
commitbafbeea4d9400099c0a653cdabe6e41f7451995e (patch)
tree84d99f369e4ace073e8131a1fb842827d0c1254a /iBean
parent93db1e2ce763e68dcbaa786991e2a554a50489db (diff)
downloadiBean-bafbeea4d9400099c0a653cdabe6e41f7451995e.tar.gz
iBean-bafbeea4d9400099c0a653cdabe6e41f7451995e.zip
Added "Done" button to the navigation bar when editing name or note for bean collection.
Diffstat (limited to 'iBean')
-rw-r--r--iBean/iBean.xcodeproj/project.xcworkspace/xcuserdata/eddiex.xcuserdatad/UserInterfaceState.xcuserstatebin30104 -> 30346 bytes
-rw-r--r--iBean/iBean/BeanCollectionInfoViewController.h6
-rw-r--r--iBean/iBean/BeanCollectionInfoViewController.m55
-rw-r--r--iBean/iBean/iPhoneStoryboard.storyboard2
4 files changed, 41 insertions, 22 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 a31d1c9..f937bb9 100644
--- a/iBean/iBean.xcodeproj/project.xcworkspace/xcuserdata/eddiex.xcuserdatad/UserInterfaceState.xcuserstate
+++ b/iBean/iBean.xcodeproj/project.xcworkspace/xcuserdata/eddiex.xcuserdatad/UserInterfaceState.xcuserstate
Binary files 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 <UIKit/UIKit.h>
@class BeanCollection;
-@interface BeanCollectionInfoViewController : UIViewController <UITextFieldDelegate, UITextViewDelegate, UIScrollViewDelegate>
+@interface BeanCollectionInfoViewController : UIViewController <UITextFieldDelegate, UITextViewDelegate>
@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 @@
</navigationItem>
<connections>
<outlet property="beanCollectionNameTextField" destination="Vla-ab-hH3" id="ZEz-IX-3Di"/>
+ <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"/>
</connections>
@@ -481,6 +482,7 @@
<relationship kind="action" name="keyboardDisplayed:" candidateClass="NSNotification"/>
<relationship kind="action" name="keyboardHidden:" candidateClass="NSNotification"/>
<relationship kind="outlet" name="beanCollectionNameTextField" candidateClass="UITextField"/>
+ <relationship kind="outlet" name="beanCollectionNextButton" candidateClass="UIBarButtonItem"/>
<relationship kind="outlet" name="beanCollectionNoteTextView" candidateClass="UITextView"/>
<relationship kind="outlet" name="beanCollectionScrollView" candidateClass="UIScrollView"/>
</relationships>