开发者

How to add ImageButton in uitableviewcell

开发者 https://www.devze.com 2023-03-01 13:52 出处:网络
I am working on an application I want to add an imagebutton in tableviewcell and tableviewcell have already an Image(Gradient image with dimension 320 * 103) and I want to add an imagebutton on cell.

I am working on an application I want to add an imagebutton in tableviewcell and tableviewcell have already an Image(Gradient image with dimension 320 * 103) and I want to add an imagebutton on cell. we are adding but button are not display.

My code is:

UIImageView *cellimg = [[UIImageView alloc ]initWithFrame:CGRectMake(0.0, 0.0, 320.0, 103.0)];
cellimg.image = [UIImage imageNamed:@"eventListcellimage .png"];
[self.view addSubview:cellimg];
registerButton = [[UIButton alloc]init];//WithFrame:CGRectMake(210, 65, 90, 25)];
registerButton.frame = CGRectMa开发者_高级运维ke(210.0, 65.0, 90, 25);
registerButton = [UIButton buttonWithType:UIButtonTypeCustom];
[registerButton setImage:[UIImage imageNamed:@"register.png"] forState:UIControlStateNormal];
[registerButton addTarget:self action:@selector(registerButtonAction) forControlEvents:UIControlEventTouchUpInside];
[cellimg addsubView:registerButton];


Fixed this for you. Not only were you reallocating button, but also you leaked cellimg.

UIImageView *cellimg = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 103.0)];
cellimg.image = [UIImage imageNamed:@"eventListcellimage.png"];
cellimg.userInteractionEnabled = YES; //button won't work without this
[self.view addSubview:cellimg];
[cellimg release];

registerButton = [UIButton buttonWithType:UIButtonTypeCustom];
registerButton.frame = CGRectMake(210.0, 65.0, 90, 25);
[registerButton setImage:[UIImage imageNamed:@"register.png"] forState:UIControlStateNormal];
[registerButton addTarget:self action:@selector(registerButtonAction) forControlEvents:UIControlEventTouchUpInside];
[cellimg addsubView:registerButton];
0

精彩评论

暂无评论...
验证码 换一张
取 消