【发布时间】:2017-04-24 12:44:27
【问题描述】:
我读过类似的问题,但这些代码对我不起作用,所以请帮忙: 我有一个表格视图,每个单元格中有一些按钮 - 这个表格视图是用户的因素,我在该表格视图中添加了按钮 - 当用户支付了钱时,按钮隐藏在该单元格中的那个因素和另一个单元格中的另一个因素时用户没付钱不隐藏—— 这就是我所做的 我想检测按下了哪些单元格按钮?! 我知道在表格视图中我们可以检测到哪个单元格被按下但这是不同的,因为用户只是按下该单元格中的按钮而不是按下所有单元格
由于我的代码太长,我只是把表格视图代码放在这里
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCell(withIdentifier: "factorCell", for: indexPath) as! FactorCell
cell.factorTitle.text = factorTitle[indexPath.row]
cell.factorCode.text = factorCodes[indexPath.row]
cell.factorDate.text = factorDate[indexPath.row]
cell.factorHour.text = factorHour[indexPath.row]
cell.factorPrice.text = factorPrice[indexPath.row]
cell.factorCondition.text = factorConditions[indexPath.row]
cell.factorBill.tag = indexPath.row
cell.factorBill.addTarget(self,action:#selector(factorViewController.Bill), for: UIControlEvents.touchUpInside)
cell.factorDetail.tag = indexPath.row
cell.factorDetail.addTarget(self,action:#selector(factorViewController.FactorDetail), for: .touchUpInside)
if factorConditions[indexPath.row] == "پرداخت شده" {
cell.factorBill.isHidden = true
} else {
cell.factorCondition.textColor = UIColor.red
cell.factorBill.isHidden = false
}
return cell
}
这是我想要的功能: 当用户点击支付他的因素并按下按钮时 - 移动到另一个视图控制器,在该视图控制器中,用户可以在该视图控制器中看到这些数据 --
**非常感谢如果你不明白我想做什么告诉我,我会解释更多**
【问题讨论】:
-
你能用#selector(factorViewController.Bill 和#selector(factorViewController.FactorDetail)方法更新你的问题吗
-
我编辑了问题
-
只需给你的按钮一个标签。在 IBAction 检查 sender.tag
-
我添加了我的按钮作为插座而且我知道我不需要使用 IBAction 你能帮帮我吗?
标签: ios uitableview swift3 uibutton cell