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

View File

@ -34,34 +34,21 @@ static NSUInteger kNumberOfImages = 14;
- (instancetype)init
{
if (!(self = [super init]))
return nil;
_sections = [NSMutableArray array];
[_sections addObject:[NSMutableArray array]];
for (NSUInteger idx = 0, section = 0; idx < kNumberOfImages; idx++) {
NSString *name = [NSString stringWithFormat:@"image_%lu.jpg", (unsigned long)idx];
[_sections[section] addObject:[UIImage imageNamed:name]];
if ((idx + 1) % 5 == 0 && idx < kNumberOfImages - 1) {
section++;
[_sections addObject:[NSMutableArray array]];
self = [super init];
if (self) {
_sections = [NSMutableArray array];
[_sections addObject:[NSMutableArray array]];
for (NSUInteger idx = 0, section = 0; idx < kNumberOfImages; idx++) {
NSString *name = [NSString stringWithFormat:@"image_%lu.jpg", (unsigned long)idx];
[_sections[section] addObject:[UIImage imageNamed:name]];
if ((idx + 1) % 5 == 0 && idx < kNumberOfImages - 1) {
section++;
[_sections addObject:[NSMutableArray array]];
}
}
}
MosaicCollectionViewLayout *layout = [[MosaicCollectionViewLayout alloc] init];
layout.numberOfColumns = 2;
layout.headerHeight = 44.0;
_layoutInspector = [[MosaicCollectionViewLayoutInspector alloc] init];
_collectionView = [[ASCollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout asyncDataFetching:YES];
_collectionView.asyncDataSource = self;
_collectionView.asyncDelegate = self;
_collectionView.layoutInspector = _layoutInspector;
_collectionView.backgroundColor = [UIColor whiteColor];
[_collectionView registerSupplementaryNodeOfKind:UICollectionElementKindSectionHeader];
return self;
}
@ -69,12 +56,27 @@ static NSUInteger kNumberOfImages = 14;
{
[super viewDidLoad];
MosaicCollectionViewLayout *layout = [[MosaicCollectionViewLayout alloc] init];
layout.numberOfColumns = 2;
layout.headerHeight = 44.0;
_layoutInspector = [[MosaicCollectionViewLayoutInspector alloc] init];
_collectionView = [[ASCollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
_collectionView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
_collectionView.asyncDataSource = self;
_collectionView.asyncDelegate = self;
_collectionView.layoutInspector = _layoutInspector;
_collectionView.backgroundColor = [UIColor whiteColor];
[_collectionView registerSupplementaryNodeOfKind:UICollectionElementKindSectionHeader];
[self.view addSubview:_collectionView];
}
- (void)viewWillLayoutSubviews
- (void)dealloc
{
_collectionView.frame = self.view.bounds;
_collectionView.asyncDataSource = nil;
_collectionView.asyncDelegate = nil;
}
- (BOOL)prefersStatusBarHidden
@ -109,11 +111,13 @@ static NSUInteger kNumberOfImages = 14;
return [[SupplementaryNode alloc] initWithText:text];
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return _sections.count;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return [_sections[section] count];
}

View File

@ -65,6 +65,12 @@ static NSUInteger kNumberOfImages = 14;
return self;
}
- (void)dealloc
{
_collectionView.asyncDataSource = nil;
_collectionView.asyncDelegate = nil;
}
- (void)viewDidLoad
{
[super viewDidLoad];