mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Overall examples improvement
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user