aboutsummaryrefslogtreecommitdiffstats
path: root/iBean
diff options
context:
space:
mode:
Diffstat (limited to 'iBean')
-rw-r--r--iBean/iBean.xcodeproj/project.pbxproj6
-rw-r--r--iBean/iBean.xcodeproj/project.xcworkspace/xcuserdata/eddiex.xcuserdatad/UserInterfaceState.xcuserstatebin32116 -> 34150 bytes
-rw-r--r--iBean/iBean/AddBeanViewController.h2
-rw-r--r--iBean/iBean/AddBeanViewController.m20
-rw-r--r--iBean/iBean/BeanCollectionBeanListViewController.m10
-rw-r--r--iBean/iBean/EditBeanViewController.h33
-rw-r--r--iBean/iBean/EditBeanViewController.m137
-rw-r--r--iBean/iBean/iPhoneStoryboard.storyboard59
8 files changed, 248 insertions, 19 deletions
diff --git a/iBean/iBean.xcodeproj/project.pbxproj b/iBean/iBean.xcodeproj/project.pbxproj
index c17a052..e3df510 100644
--- a/iBean/iBean.xcodeproj/project.pbxproj
+++ b/iBean/iBean.xcodeproj/project.pbxproj
@@ -30,6 +30,7 @@
020C567D169F597300D8224C /* BeanCollection.m in Sources */ = {isa = PBXBuildFile; fileRef = 020C567C169F597300D8224C /* BeanCollection.m */; };
020C5680169F5E9A00D8224C /* Bean+Interface.m in Sources */ = {isa = PBXBuildFile; fileRef = 020C567F169F5E9900D8224C /* Bean+Interface.m */; };
020C5683169F5FBB00D8224C /* BeanCollection+Interface.m in Sources */ = {isa = PBXBuildFile; fileRef = 020C5682169F5FBB00D8224C /* BeanCollection+Interface.m */; };
+ 020C568F16A1CE0E00D8224C /* EditBeanViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 020C568E16A1CE0E00D8224C /* EditBeanViewController.m */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -71,6 +72,8 @@
020C567F169F5E9900D8224C /* Bean+Interface.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "Bean+Interface.m"; sourceTree = "<group>"; };
020C5681169F5FBA00D8224C /* BeanCollection+Interface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "BeanCollection+Interface.h"; sourceTree = "<group>"; };
020C5682169F5FBB00D8224C /* BeanCollection+Interface.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "BeanCollection+Interface.m"; sourceTree = "<group>"; };
+ 020C568D16A1CE0E00D8224C /* EditBeanViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EditBeanViewController.h; sourceTree = "<group>"; };
+ 020C568E16A1CE0E00D8224C /* EditBeanViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EditBeanViewController.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -221,6 +224,8 @@
children = (
020C5670169E1B0100D8224C /* AddBeanViewController.h */,
020C5671169E1B0100D8224C /* AddBeanViewController.m */,
+ 020C568D16A1CE0E00D8224C /* EditBeanViewController.h */,
+ 020C568E16A1CE0E00D8224C /* EditBeanViewController.m */,
);
name = Bean;
sourceTree = "<group>";
@@ -316,6 +321,7 @@
020C567D169F597300D8224C /* BeanCollection.m in Sources */,
020C5680169F5E9A00D8224C /* Bean+Interface.m in Sources */,
020C5683169F5FBB00D8224C /* BeanCollection+Interface.m in Sources */,
+ 020C568F16A1CE0E00D8224C /* EditBeanViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
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 c78c824..9d36b94 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/AddBeanViewController.h b/iBean/iBean/AddBeanViewController.h
index 155e18b..0778f36 100644
--- a/iBean/iBean/AddBeanViewController.h
+++ b/iBean/iBean/AddBeanViewController.h
@@ -9,7 +9,7 @@
#import <UIKit/UIKit.h>
@class BeanCollection;
-@interface AddBeanViewController : UIViewController
+@interface AddBeanViewController : UIViewController <UITextFieldDelegate>
@property (nonatomic, strong) BeanCollection *beanCollection;
@property (nonatomic, assign) BOOL editMode;
diff --git a/iBean/iBean/AddBeanViewController.m b/iBean/iBean/AddBeanViewController.m
index bebea6f..f2faa54 100644
--- a/iBean/iBean/AddBeanViewController.m
+++ b/iBean/iBean/AddBeanViewController.m
@@ -82,7 +82,7 @@
- (void) grinderSettingStepperChanged:(id)sender
{
- self.grinderSettingLabel.text = [NSString stringWithFormat:@"%1.1f", self.grinderSettingStepper.value];
+ self.grinderSettingLabel.text = [NSString stringWithFormat:@"%1.0f", self.grinderSettingStepper.value];
}
- (void) cancelBean:(id)sender
@@ -99,7 +99,6 @@
b.name = self.beanNameTextField.text;
b.grindSetting = [NSNumber numberWithDouble:self.grinderSettingStepper.value];
[self.beanCollection addBeansObject:b];
-#warning TODO - If we are in edit mode (for the bean collection) should we commit the managed context?
//Go back to the bean list.
[self dismissViewControllerAnimated:YES completion:nil];
@@ -109,4 +108,21 @@
#warning TODO - Messagebox telling user that error occured.
}
}
+
+/*****************************************************
+ Delegate
+ *****************************************************/
+#pragma mark - UITextField delagate related methods
+//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.beanNameTextField)
+ {
+ [textField resignFirstResponder];
+ return YES;
+ }
+
+ return NO;
+}
@end
diff --git a/iBean/iBean/BeanCollectionBeanListViewController.m b/iBean/iBean/BeanCollectionBeanListViewController.m
index 08b1eed..5ad05d0 100644
--- a/iBean/iBean/BeanCollectionBeanListViewController.m
+++ b/iBean/iBean/BeanCollectionBeanListViewController.m
@@ -7,6 +7,7 @@
//
#import "BeanCollectionBeanListViewController.h"
+#import "EditBeanViewController.h"
#import "AddBeanViewController.h"
#import "BeanCollection.h"
#import "Bean.h"
@@ -17,8 +18,6 @@
@implementation BeanCollectionBeanListViewController
-#warning TODO: Remove this method, probably not needed when using storyboards
-/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
@@ -27,7 +26,6 @@
}
return self;
}
-*/
- (void)viewDidLoad
{
@@ -60,7 +58,8 @@
}
else if ([segue.identifier isEqualToString:@"EditBeanSegue"])
{
- //TODO
+ EditBeanViewController *beanViewController = segue.destinationViewController;
+ [beanViewController initWithModeAndBeanCollectionAndBeanIndex:self.editMode :self.beanCollection :[self.beanListTableView indexPathForSelectedRow].row];
}
}
@@ -139,7 +138,6 @@
//Configure the cell and set its title
Bean *currentBean = [self.beanCollection.beans objectAtIndex:indexPath.row];
-#warning TODO: This may fuck things up since the beanCollection.beans set is NOT ordered?
cell.textLabel.text = currentBean.name;
return cell;
@@ -159,10 +157,8 @@
// Delete the row from the data source
if (self.beanCollection != nil)
{
-#warning TODO - Do we need to remove it via delegate, and then reload the structure or just remove it?
[self.beanCollection removeObjectFromBeansAtIndex: indexPath.row];
}
-#warning TODO - Double check that correct bean is removed!
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
diff --git a/iBean/iBean/EditBeanViewController.h b/iBean/iBean/EditBeanViewController.h
new file mode 100644
index 0000000..7d0d8fd
--- /dev/null
+++ b/iBean/iBean/EditBeanViewController.h
@@ -0,0 +1,33 @@
+//
+// EditBeanViewController.h
+// iBean
+//
+// Created by Eddie Ehlin on 2013-01-12.
+// Copyright (c) 2013 Eddie Ehlin. All rights reserved.
+//
+@class BeanCollection;
+
+@interface EditBeanViewController : UIViewController <UITextFieldDelegate>
+
+@property (nonatomic, strong) BeanCollection *beanCollection;
+@property (nonatomic, assign) BOOL editMode;
+@property (nonatomic, assign) NSUInteger editBeanIndex;
+
+/* Utility methods */
+- (void) initWithModeAndBeanCollectionAndBeanIndex:(BOOL)editMode: (BeanCollection*) bc: (NSUInteger) beanIndex;
+- (void) initViewController;
+
+/* UI Outlets */
+@property (weak, nonatomic) IBOutlet UITextField *beanNameTextField;
+@property (weak, nonatomic) IBOutlet UILabel *amountLabel;
+@property (weak, nonatomic) IBOutlet UIStepper *amountStepper;
+@property (weak, nonatomic) IBOutlet UILabel *grinderSettingLabel;
+@property (weak, nonatomic) IBOutlet UIStepper *grinderSettingStepper;
+
+
+/* UI Actions */
+- (IBAction) amountStepperChanged:(id)sender;
+- (IBAction) grinderSettingStepperChanged:(id)sender;
+- (IBAction) commitBean:(id)sender;
+
+@end
diff --git a/iBean/iBean/EditBeanViewController.m b/iBean/iBean/EditBeanViewController.m
new file mode 100644
index 0000000..5f1a84c
--- /dev/null
+++ b/iBean/iBean/EditBeanViewController.m
@@ -0,0 +1,137 @@
+//
+// EditBeanViewController.m
+// iBean
+//
+// Created by Eddie Ehlin on 2013-01-12.
+// Copyright (c) 2013 Eddie Ehlin. All rights reserved.
+//
+
+#import "BeanCollection+Interface.h"
+#import "Bean+Interface.h"
+#import "EditBeanViewController.h"
+
+@interface EditBeanViewController ()
+
+@end
+
+@implementation EditBeanViewController
+
+- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
+{
+ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
+ if (self) {
+ // Custom initialization
+ }
+ return self;
+}
+
+- (void)viewDidLoad
+{
+ [super viewDidLoad];
+ // 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.
+}
+
+/*****************************************************
+ Utility methods
+ *****************************************************/
+- (void) initWithModeAndBeanCollectionAndBeanIndex:(BOOL)editMode: (BeanCollection*) bc: (NSUInteger) beanIndex
+{
+ self.editMode = editMode;
+ self.beanCollection = bc;
+ self.editBeanIndex = beanIndex;
+ if (bc == nil)
+ {
+ NSLog(@"EditBeanViewController - initWithModeAndBeanCollectionAndBeanIndex: Received bogus bean collection (nil)!");
+ }
+}
+
+- (void) initViewController
+{
+ NSLog(@"EditBeanViewController - initViewController");
+
+ if (self.editMode == YES)
+ {
+ //TODO: Update UI to refelect edit mode.
+
+ //+ set UI controls with values from beanCollection.
+ NSLog(@"EditBeanViewController - in edit state");
+ }
+ else
+ {
+ NSLog(@"EditBeanViewController - in add new state");
+ }
+
+ //Fetch bean data from the collection and populate the ui.
+ Bean *b = [self.beanCollection.beans objectAtIndex:self.editBeanIndex];
+ if (b != nil)
+ {
+ self.beanNameTextField.text = b.name;
+ self.amountLabel.text = [NSString stringWithFormat:@"%1.1f", [b.amount doubleValue]];
+ self.amountStepper.value = [b.amount doubleValue];
+ self.grinderSettingLabel.text = [NSString stringWithFormat:@"%1.0f", [b.grindSetting doubleValue]];
+ self.grinderSettingStepper.value = [b.grindSetting doubleValue];
+ }
+}
+
+/*****************************************************
+ UI Actions
+ *****************************************************/
+#pragma mark - IBActions
+- (void) amountStepperChanged:(id)sender
+{
+ self.amountLabel.text = [NSString stringWithFormat:@"%1.1f", self.amountStepper.value];
+}
+
+- (void) grinderSettingStepperChanged:(id)sender
+{
+ self.grinderSettingLabel.text = [NSString stringWithFormat:@"%1.0f", self.grinderSettingStepper.value];
+}
+
+- (void) commitBean:(id)sender
+{
+ NSLog(@"EditBeanViewController - commitBean");
+ if (self.beanCollection != nil)
+ {
+ Bean *b = [self.beanCollection.beans objectAtIndex:self.editBeanIndex];
+ if (b != nil)
+ {
+ b.name = self.beanNameTextField.text;
+ b.amount = [NSNumber numberWithDouble:self.amountStepper.value];
+ b.grindSetting = [NSNumber numberWithDouble:self.grinderSettingStepper.value];
+
+ //Lets return to the list
+ [[self navigationController] popViewControllerAnimated:YES];
+ }
+ }
+}
+
+/*****************************************************
+ Delegate
+ *****************************************************/
+#pragma mark - UITextField delagate related methods
+//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.beanNameTextField)
+ {
+ [textField resignFirstResponder];
+ return YES;
+ }
+
+ return NO;
+}
+
+@end
diff --git a/iBean/iBean/iPhoneStoryboard.storyboard b/iBean/iBean/iPhoneStoryboard.storyboard
index 9fbf609..1c18432 100644
--- a/iBean/iBean/iPhoneStoryboard.storyboard
+++ b/iBean/iBean/iPhoneStoryboard.storyboard
@@ -338,10 +338,10 @@
</objects>
<point key="canvasLocation" x="2777" y="403"/>
</scene>
- <!--View Controller - Edit bean-->
+ <!--Edit Bean View Controller - Edit bean-->
<scene sceneID="Uz1-1o-7sM">
<objects>
- <viewController id="4CQ-Gd-pSW" sceneMemberID="viewController">
+ <viewController id="4CQ-Gd-pSW" customClass="EditBeanViewController" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="3Yp-lm-I9K">
<rect key="frame" x="0.0" y="64" width="320" height="504"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
@@ -356,7 +356,10 @@
<constraint firstAttribute="width" constant="281" id="Y2Z-eE-IrG"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
- <textInputTraits key="textInputTraits"/>
+ <textInputTraits key="textInputTraits" returnKeyType="done"/>
+ <connections>
+ <outlet property="delegate" destination="4CQ-Gd-pSW" id="yIu-PF-Q7X"/>
+ </connections>
</textField>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Amount (g):" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="qb5-I0-339">
<constraints>
@@ -366,14 +369,22 @@
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
- <stepper opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" maximumValue="500" stepValue="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="blJ-S2-uV9"/>
+ <stepper opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" maximumValue="500" stepValue="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="blJ-S2-uV9">
+ <connections>
+ <action selector="amountStepperChanged:" destination="4CQ-Gd-pSW" eventType="valueChanged" id="Et6-V6-rh1"/>
+ </connections>
+ </stepper>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Grinder setting:" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="bUi-2X-Nne">
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
- <stepper opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" maximumValue="1000" translatesAutoresizingMaskIntoConstraints="NO" id="bIT-x3-0cE"/>
- <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="###" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="o6F-sa-dYn">
+ <stepper opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" maximumValue="1000" translatesAutoresizingMaskIntoConstraints="NO" id="bIT-x3-0cE">
+ <connections>
+ <action selector="grinderSettingStepperChanged:" destination="4CQ-Gd-pSW" eventType="valueChanged" id="cO7-pm-X7v"/>
+ </connections>
+ </stepper>
+ <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="0.0" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="o6F-sa-dYn">
<constraints>
<constraint firstAttribute="width" constant="42" id="d7l-M7-k5y"/>
</constraints>
@@ -381,7 +392,10 @@
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
- <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="###" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="nPM-k1-zYG">
+ <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="0.0" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="nPM-k1-zYG">
+ <constraints>
+ <constraint firstAttribute="width" constant="29" id="qX5-Yz-NSx"/>
+ </constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
@@ -408,8 +422,19 @@
</constraints>
</view>
<navigationItem key="navigationItem" title="Edit bean" id="A3D-NS-DOt">
- <barButtonItem key="rightBarButtonItem" systemItem="done" id="Dcw-BA-AX2"/>
+ <barButtonItem key="rightBarButtonItem" systemItem="save" id="Dcw-BA-AX2">
+ <connections>
+ <action selector="commitBean:" destination="4CQ-Gd-pSW" id="cCA-oY-PxO"/>
+ </connections>
+ </barButtonItem>
</navigationItem>
+ <connections>
+ <outlet property="amountLabel" destination="o6F-sa-dYn" id="Sok-S2-Iqp"/>
+ <outlet property="amountStepper" destination="blJ-S2-uV9" id="HcC-YU-z8J"/>
+ <outlet property="beanNameTextField" destination="GEQ-Pg-YlJ" id="n8o-hq-x9t"/>
+ <outlet property="grinderSettingLabel" destination="nPM-k1-zYG" id="W1J-hC-crl"/>
+ <outlet property="grinderSettingStepper" destination="bIT-x3-0cE" id="8dr-VO-NQA"/>
+ </connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="WEn-wW-jac" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
@@ -479,7 +504,10 @@
<constraint firstAttribute="width" constant="281" id="WQ1-oe-YTn"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
- <textInputTraits key="textInputTraits"/>
+ <textInputTraits key="textInputTraits" returnKeyType="done"/>
+ <connections>
+ <outlet property="delegate" destination="YXO-0S-PzZ" id="MbB-Fx-v6j"/>
+ </connections>
</textField>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Amount (g):" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="K5g-ln-AQ0">
<constraints>
@@ -639,6 +667,19 @@
<relationship kind="outlet" name="beanCollectionsListEditButton" candidateClass="UIBarButtonItem"/>
</relationships>
</class>
+ <class className="EditBeanViewController" superclassName="UIViewController">
+ <source key="sourceIdentifier" type="project" relativePath="./Classes/EditBeanViewController.h"/>
+ <relationships>
+ <relationship kind="action" name="amountStepperChanged:"/>
+ <relationship kind="action" name="commitBean:"/>
+ <relationship kind="action" name="grinderSettingStepperChanged:"/>
+ <relationship kind="outlet" name="amountLabel" candidateClass="UILabel"/>
+ <relationship kind="outlet" name="amountStepper" candidateClass="UIStepper"/>
+ <relationship kind="outlet" name="beanNameTextField" candidateClass="UITextField"/>
+ <relationship kind="outlet" name="grinderSettingLabel" candidateClass="UILabel"/>
+ <relationship kind="outlet" name="grinderSettingStepper" candidateClass="UIStepper"/>
+ </relationships>
+ </class>
<class className="InstaBeanViewController" superclassName="UIViewController">
<source key="sourceIdentifier" type="project" relativePath="./Classes/InstaBeanViewController.h"/>
<relationships>