添加按钮到uitableviewcell并没有出现

时间:2013-08-21 23:33:01

标签: ios

我正在为UITableViewCell中的cellForRowAtIndexPath:添加删除按钮 但按钮没有出现。

double deleteYOffset=10;
double deleteW=100;
double deleteH=100;

UIButton *deleteButton =[UIButton buttonWithType:UIButtonTypeCustom];
deleteButton.frame=CGRectMake(imageXoffset, deleteYOffset, deleteW, deleteH);
UIImage *image = [UIImage imageNamed:@"Delete.png"];
[deleteButton setBackgroundColor:[UIColor greenColor]];
[deleteButton setImage:image forState:UIControlStateNormal];
[[cell contentView ]addSubview:deleteButton];

2 个答案:

答案 0 :(得分:2)

没有足够的代表因此无法评论,但您似乎缺少imageXoffset

我用以下代码复制了你的代码:

double imageXoffset = 10;

并且能够看到我的细胞的按钮渲染。基于此,我猜测你的偏移设置不正确并且在视图之外渲染了按钮。

还考虑将视图代码移动到CustomCell类中,并将CustomCell实例化为cellForRowAtIndexPath。您应该能够通过xCode UI绑定图像,并绕过必须定义偏移/高度和宽度。

答案 1 :(得分:1)

Delete.PNG是IOS的保留字....我将图像更改为删除1并且它有效。

相关问题