Skip to content

Commit

Permalink
Empty view WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
soffes committed May 24, 2012
1 parent 493126e commit 1d4475e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
1 change: 0 additions & 1 deletion SSManagedTableViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
@property (nonatomic) BOOL clearsSelectionOnViewWillAppear;

- (id)initWithStyle:(UITableViewStyle)style;

- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath;

@end
1 change: 1 addition & 0 deletions SSManagedTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ - (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)


- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
[super controllerDidChangeContent:controller];
if (self.ignoreChange) {
return;
}
Expand Down
1 change: 1 addition & 0 deletions SSManagedViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
@property (nonatomic, strong) SSManagedObject *managedObject;
@property (nonatomic, strong) NSFetchedResultsController *fetchedResultsController;
@property (nonatomic, assign) BOOL ignoreChange;
@property (nonatomic, strong) UIView *emptyView;

+ (Class)fetchedResultsControllerClass;
- (NSFetchRequest *)fetchRequest;
Expand Down
54 changes: 54 additions & 0 deletions SSManagedViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@
#import "SSManagedViewController.h"
#import "SSManagedObject.h"

@interface SSManagedViewController ()
- (void)_updateEmptyView:(BOOL)animated;
@end

@implementation SSManagedViewController

@synthesize managedObject = _managedObject;
@synthesize fetchedResultsController = _fetchedResultsController;
@synthesize ignoreChange = _ignoreChange;
@synthesize emptyView = _emptyView;

#pragma mark - Accessors

Expand Down Expand Up @@ -43,6 +48,14 @@ - (void)dealloc {
}


#pragma mark - UIViewController

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self _updateEmptyView:NO];
}


#pragma mark - Configuration

+ (Class)fetchedResultsControllerClass {
Expand Down Expand Up @@ -105,4 +118,45 @@ - (id)objectForViewIndexPath:(NSIndexPath *)indexPath {
return [self.fetchedResultsController objectAtIndexPath:[self fetchedIndexPathForViewIndexPath:indexPath]];
}


#pragma mark - Private

- (void)_updateEmptyView:(BOOL)animated {
if (!self.emptyView) {
return;
}

NSInteger objectCount = self.fetchedResultsController.fetchedObjects.count;
if (self.emptyView.superview && objectCount > 0) {
if (animated) {
[UIView animateWithDuration:0.3 delay:0.0f options:UIViewAnimationOptionAllowUserInteraction animations:^{
self.emptyView.alpha = 0.0f;
} completion:^(BOOL finished) {
[self.emptyView removeFromSuperview];
}];
} else {
[self.emptyView removeFromSuperview];
}
} else if (!self.emptyView.superview && objectCount == 0) {
if (animated) {
self.emptyView.alpha = 0.0f;
[self.view addSubview:self.emptyView];
[UIView animateWithDuration:0.3 delay:0.0f options:UIViewAnimationOptionAllowUserInteraction animations:^{
self.emptyView.alpha = 1.0f;
} completion:nil];
} else {
self.emptyView.frame = self.view.bounds;
self.emptyView.alpha = 1.0f;
[self.view addSubview:self.emptyView];
}
}
}


#pragma mark - NSFetchedResultsControllerDelegate

- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
[self _updateEmptyView:YES];
}

@end

0 comments on commit 1d4475e

Please sign in to comment.