I creating set of objects same custom type. All objects have methods showDeleteButton
had hideDeleteButton
.
I found that when I hide delete button (remove it) button which was pressed has retainCounter == 2.
Here the code:
-(void)showDeleteButton {
if(!isDeleteButtonLoaded) { // Check that method was't triggered twice
UIButton *aDeleteButton = [[UIButton alloc] initWithFrame:CGRectMake(-3, -7, 30, 29)]; // RC == 1
[aDeleteButton setImage:[UIImage imageNamed:@"close_button.png"] forState:UIControlStateNormal];
[self addSubview:aDeleteButton]; // RC == 2
[aDeleteButton addTarget:self action:@selector(deleteButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
deleteButton = aDeleteButton;
[aDeleteButton release]; // RC == 1
isDeleteButtonLoaded = YES;
NSLog(@"delete button retain count (created): %d", [deleteButton retainCount]);
[self setNeedsDisplay];
}
}
-(void)deleteButtonPressed:(id)sender {
[delegate deleteImageAtPath:self.imageFullPath];
}
-(void)hideDeleteButton {
if(isDeleteButtonLoaded) {
NSLog(@"delete button retain count (before): %d", [deleteButton retainCount]); // RC == 1
[deleteButton removeFromSuperview]; // RC == 0
deleteButton = nil;
isDeleteButtonLoaded = NO;
[self setNeedsDisplay];
}
}
So for pressed button NSLog in the second method displays RC == 2! Any ideas? I'm 100% sure that deleteButton isn't accessible from outside the class.