Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: ssv/MyDay
base: f7995eef86
...
head fork: ssv/MyDay
compare: ca67084340
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Commits on Apr 02, 2012
Stas Sviridenko removed debug logging 2122824
Stas Sviridenko active/inactive switch ca67084
View
3  MyDay/MasterViewController.h
@@ -19,6 +19,9 @@
@property (strong, nonatomic) NSFetchedResultsController *fetchedResultsController;
@property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;
+@property (assign, nonatomic) BOOL active;
+
- (IBAction)iconTapped:(id)sender;
+- (IBAction)activeFilterSwitched:(id)sender;
@end
View
53 MyDay/MasterViewController.m
@@ -22,6 +22,8 @@ @implementation MasterViewController
@synthesize fetchedResultsController = __fetchedResultsController;
@synthesize managedObjectContext = __managedObjectContext;
+@synthesize active;
+
- (void)awakeFromNib
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
@@ -79,12 +81,7 @@ - (void)insertNewObject:(id)sender
[newManagedObject setValue:preferredDate forKey:@"date"];
[newManagedObject setValue:@"" forKey:@"title"];
-
- // TODO remove me!
- BOOL checked = rand() % 2;
- NSLog(@"new item will be %d", checked);
- [newManagedObject setValue:[NSNumber numberWithBool:checked] forKey:@"done"];
-
+
// Save the context.
NSError *error = nil;
if (![context save:&error]) {
@@ -171,12 +168,7 @@ - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
#pragma mark - Fetched results controller
-- (NSFetchedResultsController *)fetchedResultsController
-{
- if (__fetchedResultsController != nil) {
- return __fetchedResultsController;
- }
-
+- (NSFetchRequest *)prepareFetchRequestForTaskState:(BOOL)taskState {
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
// Edit the entity name as appropriate.
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Task" inManagedObjectContext:self.managedObjectContext];
@@ -188,11 +180,17 @@ - (NSFetchedResultsController *)fetchedResultsController
// Edit the sort key as appropriate.
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObjects:sortDescriptor, nil];
-
[fetchRequest setSortDescriptors:sortDescriptors];
- // Edit the section name key path and cache name if appropriate.
- // nil for section name key path means "no sections".
+ NSPredicate *predicate = [NSPredicate predicateWithFormat:@"done = %d", self.active];
+ [fetchRequest setPredicate:predicate];
+
+ return fetchRequest;
+}
+
+- (void)fetchTasksForState:(BOOL)taskState {
+ // TODO it smells :(
+ NSFetchRequest *fetchRequest = [self prepareFetchRequestForTaskState:taskState];
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:self.managedObjectContext
sectionNameKeyPath:@"date.dateKind"
@@ -202,12 +200,22 @@ - (NSFetchedResultsController *)fetchedResultsController
NSError *error = nil;
if (![self.fetchedResultsController performFetch:&error]) {
- // Replace this implementation with code to handle the error appropriately.
- // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
+ // Replace this implementation with code to handle the error appropriately.
+ // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
+}
+
+- (NSFetchedResultsController *)fetchedResultsController
+{
+ if (__fetchedResultsController != nil) {
+ return __fetchedResultsController;
+ }
+
+ [self fetchTasksForState:self.active];
+
return __fetchedResultsController;
}
@@ -291,13 +299,20 @@ - (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPa
- (IBAction)iconTapped:(id)sender {
UITableViewCell *cell = (UITableViewCell *)((UITapGestureRecognizer *)sender).view.superview.superview;
- NSLog(@"%@", cell);
NSIndexPath *indexPathForClickedCell = [self.tableView indexPathForCell:cell];
- NSLog(@"%@", indexPathForClickedCell);
id clickedObject = [self.fetchedResultsController objectAtIndexPath:indexPathForClickedCell];
BOOL done = [(NSNumber *)[clickedObject valueForKey:@"done"] boolValue];
[clickedObject setValue:[NSNumber numberWithBool:!done] forKey:@"done"];
[self.tableView reloadData];
}
+- (IBAction)activeFilterSwitched:(id)sender {
+ UISegmentedControl *segmentedControl = (UISegmentedControl *)sender;
+
+ self.active = (BOOL)segmentedControl.selectedSegmentIndex;
+ [self fetchTasksForState:self.active];
+
+ [self.tableView reloadData];
+}
+
@end
View
16 MyDay/en.lproj/MainStoryboard_iPhone.storyboard
@@ -74,7 +74,20 @@
<outlet property="delegate" destination="12" id="15"/>
</connections>
</tableView>
- <navigationItem key="navigationItem" title="Events" id="36"/>
+ <navigationItem key="navigationItem" id="36">
+ <nil key="title"/>
+ <segmentedControl key="titleView" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="bar" selectedSegmentIndex="0" id="pZ8-Wq-A8U">
+ <rect key="frame" x="74" y="7" width="172" height="30"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
+ <segments>
+ <segment title="Active"/>
+ <segment title="Completed"/>
+ </segments>
+ <connections>
+ <action selector="activeFilterSwitched:" destination="12" eventType="valueChanged" id="3oV-Q3-B6W"/>
+ </connections>
+ </segmentedControl>
+ </navigationItem>
</tableViewController>
</objects>
<point key="canvasLocation" x="459" y="64"/>
@@ -219,6 +232,7 @@
<class className="MasterViewController" superclassName="UITableViewController">
<source key="sourceIdentifier" type="project" relativePath="./Classes/MasterViewController.h"/>
<relationships>
+ <relationship kind="action" name="activeFilterSwitched:"/>
<relationship kind="action" name="iconTapped:"/>
</relationships>
</class>

No commit comments for this range

Something went wrong with that request. Please try again.