Adding a delegate to a custom UITableViewCell (bad access error)

£可爱£侵袭症+ 提交于 2019-11-28 11:09:06

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.

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!