From 9949c6348d2e7bf4355c852b907322b7b7bff2a5 Mon Sep 17 00:00:00 2001 From: Hannah Troisi Date: Mon, 7 Nov 2016 15:55:09 -0800 Subject: [PATCH] [Examples] update example projects to 2.0 API (#2568) * update example projects to latest Collection / Table API * udpate delegate / data source methods --- .../ASCollectionView/Sample/ViewController.m | 34 +++++++++---------- .../ASViewController/Sample/ViewController.m | 2 +- .../Sample/OverviewComponentsViewController.m | 2 +- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/examples/ASCollectionView/Sample/ViewController.m b/examples/ASCollectionView/Sample/ViewController.m index 56a1d510..526d47ab 100644 --- a/examples/ASCollectionView/Sample/ViewController.m +++ b/examples/ASCollectionView/Sample/ViewController.m @@ -23,7 +23,7 @@ @interface ViewController () -@property (nonatomic, strong) ASCollectionView *collectionView; +@property (nonatomic, strong) ASCollectionNode *collectionNode; @property (nonatomic, strong) NSArray *data; @end @@ -34,8 +34,8 @@ - (void)dealloc { - self.collectionView.asyncDataSource = nil; - self.collectionView.asyncDelegate = nil; + self.collectionNode.dataSource = nil; + self.collectionNode.delegate = nil; NSLog(@"ViewController is deallocing"); } @@ -50,19 +50,19 @@ // 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.asyncDataSource = self; - self.collectionView.asyncDelegate = self; + self.collectionNode = [[ASCollectionNode alloc] initWithFrame:self.view.bounds collectionViewLayout:layout]; + self.collectionNode.dataSource = self; + self.collectionNode.delegate = self; - self.collectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - self.collectionView.backgroundColor = [UIColor whiteColor]; + self.collectionNode.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + self.collectionNode.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.collectionNode registerSupplementaryNodeOfKind:UICollectionElementKindSectionHeader]; + [self.collectionNode registerSupplementaryNodeOfKind:UICollectionElementKindSectionFooter]; - [self.view addSubview:self.collectionView]; + [self.view addSubnode:self.collectionNode]; #if !SIMULATE_WEB_RESPONSE self.navigationItem.leftItemsSupplementBackButton = YES; @@ -103,12 +103,12 @@ { // 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 reloadData]; + [self.collectionNode reloadData]; } #pragma mark - ASCollectionView Data Source -- (ASCellNodeBlock)collectionView:(ASCollectionView *)collectionView nodeBlockForItemAtIndexPath:(NSIndexPath *)indexPath; +- (ASCellNodeBlock)collectionNode:(ASCollectionNode *)collectionNode nodeBlockForItemAtIndexPath:(NSIndexPath *)indexPath; { NSString *text = [NSString stringWithFormat:@"[%zd.%zd] says hi", indexPath.section, indexPath.item]; return ^{ @@ -116,7 +116,7 @@ }; } -- (ASCellNode *)collectionView:(ASCollectionView *)collectionView nodeForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath +- (ASCellNode *)collectionNode:(ASCollectionNode *)collectionNode nodeForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { NSString *text = [kind isEqualToString:UICollectionElementKindSectionHeader] ? @"Header" : @"Footer"; SupplementaryNode *node = [[SupplementaryNode alloc] initWithText:text]; @@ -125,12 +125,12 @@ return node; } -- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section +- (NSInteger)collectionNode:(ASCollectionNode *)collectionNode numberOfItemsInSection:(NSInteger)section { return 10; } -- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView +- (NSInteger)numberOfSectionsInCollectionView:(ASCollectionNode *)collectionNode { #if SIMULATE_WEB_RESPONSE return _data == nil ? 0 : 100; @@ -150,7 +150,7 @@ // unlock the data source to enable data source updating. } -- (void)collectionView:(UICollectionView *)collectionView willBeginBatchFetchWithContext:(ASBatchContext *)context +- (void)collectionNode:(ASCollectionNode *)collectionNode willBeginBatchFetchWithContext:(ASBatchContext *)context { NSLog(@"fetch additional content"); [context completeBatchFetching:YES]; diff --git a/examples/ASViewController/Sample/ViewController.m b/examples/ASViewController/Sample/ViewController.m index 2b3cb1d2..04b03c72 100644 --- a/examples/ASViewController/Sample/ViewController.m +++ b/examples/ASViewController/Sample/ViewController.m @@ -66,7 +66,7 @@ { [super viewWillAppear:animated]; - [self.tableNode deselectRowAtIndexPath:self.tableNode.view.indexPathForSelectedRow animated:YES]; + [self.tableNode deselectRowAtIndexPath:self.tableNode.indexPathForSelectedRow animated:YES]; } diff --git a/examples/AsyncDisplayKitOverview/Sample/OverviewComponentsViewController.m b/examples/AsyncDisplayKitOverview/Sample/OverviewComponentsViewController.m index c343d74a..798c9e2a 100644 --- a/examples/AsyncDisplayKitOverview/Sample/OverviewComponentsViewController.m +++ b/examples/AsyncDisplayKitOverview/Sample/OverviewComponentsViewController.m @@ -140,7 +140,7 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr { [super viewWillAppear:animated]; - [_tableNode deselectRowAtIndexPath:_tableNode.view.indexPathForSelectedRow animated:YES]; + [_tableNode deselectRowAtIndexPath:_tableNode.indexPathForSelectedRow animated:YES]; }