Overall examples improvement

This commit is contained in:
Michael Schneider
2016-02-24 20:20:00 -08:00
parent 6bf150bc65
commit bb35470c72
5 changed files with 82 additions and 85 deletions

View File

@@ -18,6 +18,7 @@
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Push Details" style:UIBarButtonItemStylePlain target:self action:@selector(pushNewViewController)];
}

View File

@@ -17,9 +17,11 @@
static CGFloat kInsets = 15.0;
@implementation SupplementaryNode {
ASTextNode *_textNode;
}
@interface SupplementaryNode ()
@property (nonatomic, strong) ASTextNode *textNode;
@end
@implementation SupplementaryNode
- (instancetype)initWithText:(NSString *)text
{
@@ -37,7 +39,7 @@ static CGFloat kInsets = 15.0;
{
ASCenterLayoutSpec *center = [[ASCenterLayoutSpec alloc] init];
center.centeringOptions = ASCenterLayoutSpecCenteringXY;
center.child = _textNode;
center.child = self.textNode;
UIEdgeInsets insets = UIEdgeInsetsMake(kInsets, kInsets, kInsets, kInsets);
return [ASInsetLayoutSpec insetLayoutSpecWithInsets:insets child:center];
}
@@ -47,9 +49,9 @@ static CGFloat kInsets = 15.0;
- (NSDictionary *)textAttributes
{
return @{
NSFontAttributeName: [UIFont systemFontOfSize:18.0],
NSForegroundColorAttributeName: [UIColor whiteColor],
};
NSFontAttributeName: [UIFont systemFontOfSize:18.0],
NSForegroundColorAttributeName: [UIColor whiteColor],
};
}
@end

View File

@@ -15,50 +15,48 @@
#import "SupplementaryNode.h"
#import "ItemNode.h"
@interface ViewController ()
@property (nonatomic, strong) ASCollectionView *collectionView;
@property (nonatomic, strong) NSArray *data;
@end
@interface ViewController () <ASCollectionViewDataSource, ASCollectionViewDelegateFlowLayout>
{
ASCollectionView *_collectionView;
NSArray *_data;
}
@end
@implementation ViewController
#pragma mark -
#pragma mark UIViewController.
- (instancetype)init
- (void)dealloc
{
if (!(self = [super init]))
return nil;
self.collectionView.asyncDataSource = nil;
self.collectionView.asyncDelegate = nil;
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.headerReferenceSize = CGSizeMake(50.0, 50.0);
layout.footerReferenceSize = CGSizeMake(50.0, 50.0);
_collectionView = [[ASCollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_collectionView.asyncDataSource = self;
_collectionView.asyncDelegate = self;
_collectionView.backgroundColor = [UIColor whiteColor];
[_collectionView registerSupplementaryNodeOfKind:UICollectionElementKindSectionHeader];
[_collectionView registerSupplementaryNodeOfKind:UICollectionElementKindSectionFooter];
#if !SIMULATE_WEB_RESPONSE
self.navigationItem.leftItemsSupplementBackButton = YES;
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(reloadTapped)];
#endif
return self;
NSLog(@"ViewController is deallocing");
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view addSubview:_collectionView];
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.headerReferenceSize = CGSizeMake(50.0, 50.0);
layout.footerReferenceSize = CGSizeMake(50.0, 50.0);
self.collectionView = [[ASCollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
self.collectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.collectionView.asyncDataSource = self;
self.collectionView.asyncDelegate = self;
self.collectionView.backgroundColor = [UIColor whiteColor];
[self.collectionView registerSupplementaryNodeOfKind:UICollectionElementKindSectionHeader];
[self.collectionView registerSupplementaryNodeOfKind:UICollectionElementKindSectionFooter];
[self.view addSubview:self.collectionView];
#if !SIMULATE_WEB_RESPONSE
self.navigationItem.leftItemsSupplementBackButton = YES;
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(reloadTapped)];
#endif
#if SIMULATE_WEB_RESPONSE
__weak typeof(self) weakSelf = self;
@@ -86,11 +84,6 @@
#endif
}
- (void)viewWillLayoutSubviews
{
_collectionView.frame = self.view.bounds;
}
- (BOOL)prefersStatusBarHidden
{
return YES;
@@ -98,7 +91,7 @@
- (void)reloadTapped
{
[_collectionView reloadData];
[self.collectionView reloadData];
}
#pragma mark -
@@ -116,11 +109,8 @@
{
NSString *text = [kind isEqualToString:UICollectionElementKindSectionHeader] ? @"Header" : @"Footer";
SupplementaryNode *node = [[SupplementaryNode alloc] initWithText:text];
if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
node.backgroundColor = [UIColor blueColor];
} else {
node.backgroundColor = [UIColor redColor];
}
BOOL isHeaderSection = [kind isEqualToString:UICollectionElementKindSectionHeader];
node.backgroundColor = isHeaderSection ? [UIColor blueColor] : [UIColor redColor];
return node;
}
@@ -155,15 +145,9 @@
[context completeBatchFetching:YES];
}
- (UIEdgeInsets)collectionView:(ASCollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
- (UIEdgeInsets)collectionView:(ASCollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
return UIEdgeInsetsMake(20.0, 20.0, 20.0, 20.0);
}
#if SIMULATE_WEB_RESPONSE
-(void)dealloc
{
NSLog(@"ViewController is deallocing");
}
#endif
@end