如何将UITableViewCell中的按钮与其操作方法关联起来



如何在xcode中连接UITableViewCell中的按钮及其在UITableViewCell中的操作方法。

Crtl从按钮拖动到源不起作用。

创建UITableViewCell的子类。然后你可以把你的按钮挂到你的子段落中的一个动作上。将按钮连接到您自己的子类,而不是文件的所有者。

在处理自定义单元格时,请注意,您的"源"现在不是"文件所有者",而是"UITableViewCell"对象。希望这能奏效,如果没有的话-你的代码/XIB 中出现了错误

以编程方式执行。相信我,这是最简单的。每个tableViewCell都有一个contentView。因此,您所要做的就是在-tableView:cellForRowAtIndexPath:中的特定行

UIButton* cellButton= [UIButton buttonWithType:UIButtonTypeRoundedRect]; // Cane be custom as well
[cellButton addTarget:addTarget:self action:@selector(handleCellButton:) forControlEvents:UIControlEventTouchDown];
// Further changes such as text color whatever ...
[cell.contentView addSubView:cellButton];

//为按钮添加一个处理程序方法

-(void)handleCellButton:(id)sender{}

最新更新