以编程方式将按钮添加到表视图单元格

时间:2011-10-11 04:25:27

标签: ios uitableview uibutton

我可以在表视图中添加和删除单元格。如何为每个添加的单元格设置两个按钮?

1 个答案:

答案 0 :(得分:7)

将按钮添加为您单元格的子视图。而已。我已经提供了样本:

//Create your cell then do the following    
UIButton *newBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[newBtn setFrame:CGRectMake(10,5,55,55)];
[newBtn addTarget:self action:@selector(yourSelector:) forControlEvents:UIControlEventTouchUpInside];

[cell addSubview:newBtn];