Permalink
Browse files

Added task edition via the form, using KVO

  • Loading branch information...
1 parent 38a2c7c commit 369b3ffabea42fc9f0c087d3419176b7d4090263 Adrian Kosmaczewski committed Oct 7, 2009
@@ -48,6 +48,15 @@ - (IBAction)addTask:(id)sender
}
#pragma mark -
+#pragma mark KVO delegate method
+
+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
+{
+ [[DataProvider sharedDataProvider] save];
+ [self.tableView reloadData];
+}
+
+#pragma mark -
#pragma mark Table view methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
@@ -82,6 +91,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSMutableDictionary *task = [_tasks objectAtIndex:indexPath.row];
+ [task addObserver:self forKeyPath:@"name" options:0 context:NULL];
+ [task addObserver:self forKeyPath:@"done" options:0 context:NULL];
TaskDetailController *anotherViewController = [[TaskDetailController alloc] init];
anotherViewController.task = task;
[self.navigationController pushViewController:anotherViewController animated:YES];
@@ -9,7 +9,7 @@
#import <UIKit/UIKit.h>
-@interface TaskDetailController : UIViewController
+@interface TaskDetailController : UIViewController <UITextFieldDelegate>
{
@private
NSMutableDictionary *_task;
@@ -20,4 +20,6 @@
@property (nonatomic, retain) NSMutableDictionary *task;
+- (IBAction)changeDoneStatus:(id)sender;
+
@end
@@ -7,11 +7,15 @@
//
#import "TaskDetailController.h"
+#import "DataProvider.h"
@implementation TaskDetailController
@synthesize task = _task;
+#pragma mark -
+#pragma mark Init and dealloc
+
- (id)init
{
if (self = [super initWithNibName:@"TaskDetailController" bundle:nil])
@@ -25,6 +29,17 @@ - (void)dealloc
[super dealloc];
}
+#pragma mark -
+#pragma mark IBAction methods
+
+- (IBAction)changeDoneStatus:(id)sender
+{
+ [_task setObject:[NSNumber numberWithBool:_taskDoneField.on] forKey:@"done"];
+}
+
+#pragma mark -
+#pragma mark UIViewController methods
+
- (void)viewDidLoad
{
[super viewDidLoad];
@@ -44,4 +59,14 @@ - (void)didReceiveMemoryWarning
[super didReceiveMemoryWarning];
}
+#pragma mark -
+#pragma mark UITextFieldDelegate methods
+
+- (BOOL)textFieldShouldReturn:(UITextField *)textField
+{
+ [_taskNameField resignFirstResponder];
+ [_task setObject:_taskNameField.text forKey:@"name"];
+ return YES;
+}
+
@end
@@ -87,7 +87,7 @@
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
<bool key="IBUIUserInteractionEnabled">NO</bool>
- <string key="IBUIText">Status</string>
+ <string key="IBUIText">Done</string>
<reference key="IBUITextColor" ref="4729480"/>
<nil key="IBUIHighlightedColor"/>
<int key="IBUIBaselineAdjustment">1</int>
@@ -146,6 +146,23 @@
</object>
<int key="connectionID">10</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBCocoaTouchOutletConnection" key="connection">
+ <string key="label">delegate</string>
+ <reference key="source" ref="1047517417"/>
+ <reference key="destination" ref="372490531"/>
+ </object>
+ <int key="connectionID">11</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBCocoaTouchEventConnection" key="connection">
+ <string key="label">changeDoneStatus:</string>
+ <reference key="source" ref="663717682"/>
+ <reference key="destination" ref="372490531"/>
+ <int key="IBEventType">13</int>
+ </object>
+ <int key="connectionID">12</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -242,14 +259,18 @@
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">10</int>
+ <int key="maxID">12</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBPartialClassDescription">
<string key="className">TaskDetailController</string>
<string key="superclassName">UIViewController</string>
+ <object class="NSMutableDictionary" key="actions">
+ <string key="NS.key.0">changeDoneStatus:</string>
+ <string key="NS.object.0">id</string>
+ </object>
<object class="NSMutableDictionary" key="outlets">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">

0 comments on commit 369b3ff

Please sign in to comment.