I\'m trying to add a custom delegate to a custom UITableViewCell of mine.
On this cell I have a button which need to fire a method in the ViewController where the UI
This question has been solved. The problem wasn't in the delegate and unrelated to the button issues in the other answers. The problem was lying in the access of a cell in the heightForRowAtIndexpath: and was easily solved once figured out.
I was kindly pointed to the right direction by jrturton and for this he has my thanks.
At first your interface called MyTableViewCell, implementation - iPadCheckTableViewCell. I think both should have the same name.
And create button like this:
self.myButton = [UIButton buttonWithType:UIButtonTypeCustom]; // instead of self.myButton = [[UIButton alloc] init]; - it's a memory leak
I have heard that synthesized accessors should not be used during init
. Try to do all the setup code using the ivars directly:
myButton = [[UIButton alloc] init];
myButton.backgroundColor = [UIColor clearColor];
myButton.frame = CGRectMake(5, 0, 10, 32); myButton.titleLabel.adjustsFontSizeToFitWidth = YES;
[myButton addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
[contentView addSubview:myButton];
If you change your button creation to [UIButton buttonWithType:UIButtonTypeCustom];
as beryllium rightly suggests, then you will also need to retain
it.