Skip to content

Commit

Permalink
added a counter
Browse files Browse the repository at this point in the history
  • Loading branch information
avnerbarr committed Oct 16, 2013
1 parent ba85e08 commit 0127fce
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "testApp/ViewController.m"
timestampString = "403635832.541771"
timestampString = "403650153.318171"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "19"
endingLineNumber = "19"
landmarkName = "-prepareForReuse"
startingLineNumber = "25"
endingLineNumber = "25"
landmarkName = "+count"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
Expand Down
30 changes: 26 additions & 4 deletions testApp/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,46 @@

@interface Cell : UICollectionViewCell


@end

@implementation Cell
static int i;
+(void)count:(int)delta
{

static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
i = 0;
});
i+=delta;
NSLog(@"i = %d",i);
}
-(void)prepareForReuse
{
[[self class] count:-1];
NSLog(@"Prepare For Reuse");
}

-(void)dealloc
{

NSLog(@"Dealloc");
}

-(id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
[[self class] count:1];
NSLog(@"init");
return self;
}
@end

@interface ViewController () <UICollectionViewDataSource>
@interface ViewController () <UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

@property (nonatomic,strong) UICollectionView *collectionView;
@property (nonatomic,strong) NSMutableSet *collectionViewCells;
@end

@implementation ViewController
Expand All @@ -46,6 +61,8 @@ - (void)viewDidLoad
[self.view addSubview:self.collectionView];
self.collectionView.dataSource = self;
[self.collectionView registerClass:[Cell class] forCellWithReuseIdentifier:@"a"];
self.collectionViewCells = [NSMutableSet new];

// Do any additional setup after loading the view, typically from a nib.
}

Expand All @@ -63,9 +80,14 @@ - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSe
// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"a" forIndexPath:indexPath];
cell.backgroundColor = [UIColor redColor];
return cell;
Cell *c = [self.collectionView dequeueReusableCellWithReuseIdentifier:@"a" forIndexPath:indexPath];
c.backgroundColor = [UIColor redColor];
return c;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(60, 60);
}

@end

0 comments on commit 0127fce

Please sign in to comment.