clean up ASCollectionView example project (#2384)

This commit is contained in:
Hannah Troisi
2016-10-20 17:10:20 -07:00
committed by GitHub
parent 1fbcefdbd3
commit 0dd170dde4
4 changed files with 25 additions and 11 deletions

View File

@@ -22,10 +22,12 @@
- (instancetype)initWithString:(NSString *)string
{
self = [super init];
if (self != nil) {
self.text = string;
[self updateBackgroundColor];
}
return self;
}
@@ -43,12 +45,14 @@
- (void)setSelected:(BOOL)selected
{
[super setSelected:selected];
[self updateBackgroundColor];
}
- (void)setHighlighted:(BOOL)highlighted
{
[super setHighlighted:highlighted];
[self updateBackgroundColor];
}

View File

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

View File

@@ -32,12 +32,14 @@ static CGFloat kInsets = 15.0;
- (instancetype)initWithText:(NSString *)text
{
self = [super init];
if (self != nil) {
_textNode = [[ASTextNode alloc] init];
_textNode.attributedText = [[NSAttributedString alloc] initWithString:text
attributes:[self textAttributes]];
[self addSubnode:_textNode];
}
return self;
}
@@ -47,6 +49,7 @@ static CGFloat kInsets = 15.0;
center.centeringOptions = ASCenterLayoutSpecCenteringXY;
center.child = self.textNode;
UIEdgeInsets insets = UIEdgeInsetsMake(kInsets, kInsets, kInsets, kInsets);
return [ASInsetLayoutSpec insetLayoutSpecWithInsets:insets child:center];
}

View File

@@ -21,18 +21,17 @@
#import "SupplementaryNode.h"
#import "ItemNode.h"
@interface ViewController ()
@property (nonatomic, strong) ASCollectionView *collectionView;
@property (nonatomic, strong) NSArray *data;
@end
@interface ViewController () <ASCollectionDataSource, ASCollectionViewDelegateFlowLayout>
@property (nonatomic, strong) ASCollectionView *collectionView;
@property (nonatomic, strong) NSArray *data;
@end
@implementation ViewController
#pragma mark - Lifecycle
- (void)dealloc
{
self.collectionView.asyncDataSource = nil;
@@ -52,20 +51,24 @@
// This method is deprecated because we reccommend using ASCollectionNode instead of ASCollectionView.
// This functionality & example project remains for users who insist on using ASCollectionView.
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.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.collectionView.backgroundColor = [UIColor whiteColor];
// This method is deprecated because we reccommend using ASCollectionNode instead of ASCollectionView.
// This functionality & example project remains for users who insist on using ASCollectionView.
[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)];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
target:self
action:@selector(reloadTapped)];
#endif
#if SIMULATE_WEB_RESPONSE
@@ -94,6 +97,8 @@
#endif
}
#pragma mark - Button Actions
- (void)reloadTapped
{
// This method is deprecated because we reccommend using ASCollectionNode instead of ASCollectionView.
@@ -101,8 +106,7 @@
[self.collectionView reloadData];
}
#pragma mark -
#pragma mark ASCollectionView data source.
#pragma mark - ASCollectionView Data Source
- (ASCellNodeBlock)collectionView:(ASCollectionView *)collectionView nodeBlockForItemAtIndexPath:(NSIndexPath *)indexPath;
{