Skip to content

Commit c20497b

Browse files
committed
Added autorefresh timer in example
It is useful for debugging because by regenerating the collection view with a set of cells with new random sizes we can see if they are all left aligned.
1 parent 78513dd commit c20497b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Example/Example/ExampleViewController.m

+17
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33
#import <UICollectionViewLeftAlignedLayout.h>
44

55
static NSString * const kCellIdentifier = @"CellIdentifier";
6+
static BOOL kShouldRefresh = NO;
67

78
@interface ExampleViewController () <UICollectionViewDataSource, UICollectionViewDelegateLeftAlignedLayout>
9+
810
@property (strong, nonatomic) IBOutlet UILabel *titleLabel;
911
@property (strong, nonatomic) IBOutlet UICollectionView *collectionView;
12+
13+
@property (strong, nonatomic) NSTimer *timer;
14+
1015
@end
1116

1217
@implementation ExampleViewController
@@ -29,6 +34,18 @@ - (void)viewDidLoad
2934
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:kCellIdentifier];
3035

3136
[self.view addSubview:self.collectionView];
37+
38+
if (kShouldRefresh) {
39+
self.timer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self.collectionView selector:@selector(reloadData) userInfo:nil repeats:YES];
40+
[[NSRunLoop mainRunLoop] addTimer:self.timer forMode:NSDefaultRunLoopMode];
41+
}
42+
}
43+
44+
- (void)viewWillDisappear:(BOOL)animated
45+
{
46+
[super viewWillDisappear:animated];
47+
48+
[self.timer invalidate];
3249
}
3350

3451
#pragma mark - UICollectionViewDataSource

0 commit comments

Comments
 (0)