views:

72

answers:

0

I am adding a custom UIButton to the accessoryView of UITableViewCell. I pay strict attention to the retain count and have found that the retain count is incremented to 2 when I add the button but if I put in a release or an autorelease, the code crashes on an invalid reference after loading all the tableViewCells.

First the code and then the console log with the retain counts and the exact crash message.

I test this program with every change for leaks and so this came up as soon as the code was entered, I have no other leaks or crash sources in this code.

Thanks in advance for taking a look!

Jim

UIButton * btnAdd = [UIButton buttonWithType:UIButtonTypeCustom];

NSLog( @"tour %d", [btnAdd retainCount] );

[btnAdd setImage:[UIImage imageNamed:@"ScoreIcon_C_35x35.png"]forState:UIControlStateNormal];

NSLog( @"tour %d", [btnAdd retainCount] );

CGRect buttonFrame;

buttonFrame.origin.x = 0;

buttonFrame.origin.y = 0;

buttonFrame.size.width = 25;

buttonFrame.size.height = 25;

btnAdd.frame = buttonFrame;

[btnAdd addTarget:self action:@selector(moveToSchedulingScoring:) forControlEvents:UIControlEventTouchUpInside];

NSLog( @"tour %d", [btnAdd retainCount] );

btnAdd.tag = indexPath.row;

NSLog( @"tour %d tag: %d", [btnAdd retainCount], btnAdd.tag );

cell.accessoryView = btnAdd;

NSLog( @"tour %d %@", [btnAdd retainCount], btnAdd );

[btnAdd release];

2010-07-21 13:57:28.985 tour[46413:207] tour 1

2010-07-21 13:57:28.987 tour[46413:207] tour 1

2010-07-21 13:57:28.988 tour[46413:207] tour 1

2010-07-21 13:57:28.988 tour[46413:207] tour 1 tag: 0

2010-07-21 13:57:28.989 tour[46413:207] tour 2

UIButton: 0x8868dc0; frame = (0 0; 25 25); opaque = NO; layer = CALayer: 0x886a080

2010-07-21 13:57:28.996 tour[46413:207] tour 1

2010-07-21 13:57:28.997 tour[46413:207] tour 1

2010-07-21 13:57:28.998 tour[46413:207] tour 1

2010-07-21 13:57:28.998 tour[46413:207] tour 1 tag: 1

2010-07-21 13:57:28.999 tour[46413:207] tour 2

UIButton: 0xdff9850; frame = (0 0; 25 25); opaque = NO; tag = 1; layer = CALayer: 0x745eb90

2010-07-21 13:57:29.001 tour[46413:207] tour 1

2010-07-21 13:57:29.001 tour[46413:207] tour 1

2010-07-21 13:57:29.002 tour[46413:207] tour 1

2010-07-21 13:57:29.002 tour[46413:207] tour 1 tag: 2

2010-07-21 13:57:29.003 tour[46413:207] tour 2

UIButton: 0x886c9e0; frame = (0 0; 25 25); opaque = NO; tag = 2; layer = CALayer: 0x886ca70

2010-07-21 13:57:29.004 tour[46413:207] tour 1

2010-07-21 13:57:29.005 tour[46413:207] tour 1

2010-07-21 13:57:29.006 tour[46413:207] tour 1

2010-07-21 13:57:29.006 tour[46413:207] tour 1 tag: 3

2010-07-21 13:57:29.008 tour[46413:207] tour 2

UIButton: 0x886e9f0; frame = (0 0; 25 25) opaque = NO; tag = 3; layer = CALayer: 0x886ea80

2010-07-21 13:57:29.009 tour[46413:207] * -[UIButton bounds]: message sent to deallocated instance 0x8868dc0