Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 9949c63

Browse files
Hannah Troisiappleguy
authored andcommitted
[Examples] update example projects to 2.0 API (#2568)
* update example projects to latest Collection / Table API * udpate delegate / data source methods
1 parent cc00626 commit 9949c63

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

examples/ASCollectionView/Sample/ViewController.m

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
@interface ViewController () <ASCollectionDataSource, ASCollectionViewDelegateFlowLayout>
2525

26-
@property (nonatomic, strong) ASCollectionView *collectionView;
26+
@property (nonatomic, strong) ASCollectionNode *collectionNode;
2727
@property (nonatomic, strong) NSArray *data;
2828

2929
@end
@@ -34,8 +34,8 @@ @implementation ViewController
3434

3535
- (void)dealloc
3636
{
37-
self.collectionView.asyncDataSource = nil;
38-
self.collectionView.asyncDelegate = nil;
37+
self.collectionNode.dataSource = nil;
38+
self.collectionNode.delegate = nil;
3939

4040
NSLog(@"ViewController is deallocing");
4141
}
@@ -50,19 +50,19 @@ - (void)viewDidLoad
5050

5151
// This method is deprecated because we reccommend using ASCollectionNode instead of ASCollectionView.
5252
// This functionality & example project remains for users who insist on using ASCollectionView.
53-
self.collectionView = [[ASCollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
54-
self.collectionView.asyncDataSource = self;
55-
self.collectionView.asyncDelegate = self;
53+
self.collectionNode = [[ASCollectionNode alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
54+
self.collectionNode.dataSource = self;
55+
self.collectionNode.delegate = self;
5656

57-
self.collectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
58-
self.collectionView.backgroundColor = [UIColor whiteColor];
57+
self.collectionNode.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
58+
self.collectionNode.backgroundColor = [UIColor whiteColor];
5959

6060
// This method is deprecated because we reccommend using ASCollectionNode instead of ASCollectionView.
6161
// This functionality & example project remains for users who insist on using ASCollectionView.
62-
[self.collectionView registerSupplementaryNodeOfKind:UICollectionElementKindSectionHeader];
63-
[self.collectionView registerSupplementaryNodeOfKind:UICollectionElementKindSectionFooter];
62+
[self.collectionNode registerSupplementaryNodeOfKind:UICollectionElementKindSectionHeader];
63+
[self.collectionNode registerSupplementaryNodeOfKind:UICollectionElementKindSectionFooter];
6464

65-
[self.view addSubview:self.collectionView];
65+
[self.view addSubnode:self.collectionNode];
6666

6767
#if !SIMULATE_WEB_RESPONSE
6868
self.navigationItem.leftItemsSupplementBackButton = YES;
@@ -103,20 +103,20 @@ - (void)reloadTapped
103103
{
104104
// This method is deprecated because we reccommend using ASCollectionNode instead of ASCollectionView.
105105
// This functionality & example project remains for users who insist on using ASCollectionView.
106-
[self.collectionView reloadData];
106+
[self.collectionNode reloadData];
107107
}
108108

109109
#pragma mark - ASCollectionView Data Source
110110

111-
- (ASCellNodeBlock)collectionView:(ASCollectionView *)collectionView nodeBlockForItemAtIndexPath:(NSIndexPath *)indexPath;
111+
- (ASCellNodeBlock)collectionNode:(ASCollectionNode *)collectionNode nodeBlockForItemAtIndexPath:(NSIndexPath *)indexPath;
112112
{
113113
NSString *text = [NSString stringWithFormat:@"[%zd.%zd] says hi", indexPath.section, indexPath.item];
114114
return ^{
115115
return [[ItemNode alloc] initWithString:text];
116116
};
117117
}
118118

119-
- (ASCellNode *)collectionView:(ASCollectionView *)collectionView nodeForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
119+
- (ASCellNode *)collectionNode:(ASCollectionNode *)collectionNode nodeForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
120120
{
121121
NSString *text = [kind isEqualToString:UICollectionElementKindSectionHeader] ? @"Header" : @"Footer";
122122
SupplementaryNode *node = [[SupplementaryNode alloc] initWithText:text];
@@ -125,12 +125,12 @@ - (ASCellNode *)collectionView:(ASCollectionView *)collectionView nodeForSupplem
125125
return node;
126126
}
127127

128-
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
128+
- (NSInteger)collectionNode:(ASCollectionNode *)collectionNode numberOfItemsInSection:(NSInteger)section
129129
{
130130
return 10;
131131
}
132132

133-
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
133+
- (NSInteger)numberOfSectionsInCollectionView:(ASCollectionNode *)collectionNode
134134
{
135135
#if SIMULATE_WEB_RESPONSE
136136
return _data == nil ? 0 : 100;
@@ -150,7 +150,7 @@ - (void)collectionViewUnlockDataSource:(ASCollectionView *)collectionView
150150
// unlock the data source to enable data source updating.
151151
}
152152

153-
- (void)collectionView:(UICollectionView *)collectionView willBeginBatchFetchWithContext:(ASBatchContext *)context
153+
- (void)collectionNode:(ASCollectionNode *)collectionNode willBeginBatchFetchWithContext:(ASBatchContext *)context
154154
{
155155
NSLog(@"fetch additional content");
156156
[context completeBatchFetching:YES];

examples/ASViewController/Sample/ViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ - (void)viewWillAppear:(BOOL)animated
6666
{
6767
[super viewWillAppear:animated];
6868

69-
[self.tableNode deselectRowAtIndexPath:self.tableNode.view.indexPathForSelectedRow animated:YES];
69+
[self.tableNode deselectRowAtIndexPath:self.tableNode.indexPathForSelectedRow animated:YES];
7070
}
7171

7272

examples/AsyncDisplayKitOverview/Sample/OverviewComponentsViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ - (void)viewWillAppear:(BOOL)animated
140140
{
141141
[super viewWillAppear:animated];
142142

143-
[_tableNode deselectRowAtIndexPath:_tableNode.view.indexPathForSelectedRow animated:YES];
143+
[_tableNode deselectRowAtIndexPath:_tableNode.indexPathForSelectedRow animated:YES];
144144
}
145145

146146

0 commit comments

Comments
 (0)