如何viewController
在通过 custom 给出的按钮中添加不同的点击tableViewCell
?我正在使用 Swift 4.0。
1 回答
0
对于 cellForRowAtIndexPath: 方法,根据索引路径为按钮添加标签
cell.yourbutton.tag = indexPath.row;
然后为按钮添加目标,如下所示 -
[cell.yourbutton addTarget:self action:@selector(yourButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
斯威夫特:
cell.yourbutton.addTarget(self, action: #selector(ViewController. yourButtonClicked(_:)), for: .touchUpInside)
现在根据标签类型添加代码以在此处打开视图控制器,即您的单元格索引
-(void)yourButtonClicked:(UIButton*)sender
{
if (sender.tag == 0)
{
// open view controller for index zero
}
}
斯威夫特 -
@objc func yourButtonClicked(_ sender: UIButton) {
if sender.tag == 0
{
// open view controller for index zero
}
}
于 2018-07-05T08:12:08.883 回答