在swift 3中的tableView中按下了哪个单元格按钮 [英] which cell button has pressed in tableView in swift 3

查看:227
本文介绍了在swift 3中的tableView中按下了哪个单元格按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了类似这样的问题,但这些代码对我没有用,所以请帮助:
我有一个表视图,每个单元格中有一些按钮 - 这个表视图是用户的因素,我添加了按钮到那个tableview - 当用户付钱时,按钮被隐藏在那个单元格中的那个因素中,而另一个单元格中隐藏另一个因素,当用户没有支付到付款时没有隐藏 -
这就是我做的
我想检测按钮按下的单元格?!
我知道在表格视图中我们可以检测到哪个单元格已被按下但是这是不同的,因为用户只需按下该单元格中的按钮不按下所有单元格

I have read similar questions like this but these codes didn't worked for me so please help : I have a table view with some buttons in each cells - This table view is factor for user and I added button to that tableview - when user has paid money the button is hidden in that factor in that cell and in another cell for another factor when user didn't paid the pay money is not hidden - this is what I did I want to detect which cells button has pressed ?! I know that in table view we can detect which cell has pressed But this is different because the user just press the Button in that cell Not press all of the Cell

由于我的代码太长,我只需将表格视图放在此处

As my codes are too long I Just Put the table view Codes here

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

}

这是我想要的功能:
当用户点击支付他的因子并按下按钮 - 移动到另一个视图控制器并在该视图控制器中用户可以在View Controller中看到这些数据 -

and this is the function that I want to: when User Click to pay his Factor and press the button - Move to another view Controller and in that view controller the user could see these data here in that View Controller --

**非常感谢如果你不明白我想做什么告诉我,我会解释更多**

**Thanks a lot If you didn't understand What I want to do tell me and i will Explain More **

推荐答案

  Here is update

just leave it, i explained it more simple,
create a button action in your cell class,then
Writre the code:-

> //Cell class

protocol CellDelegate: class {
    func didTapCell(index: IndexPath)
}
  var delegateCell:CellDelegate?
  var indexPath:IndexPath?
 @IBAction func buttonCellClick(_ sender: Any) {
        delegateCell?.didTapCell(index: indexPath!)
    }

> //In ViewController

 cell.delegateCell = self
 cell.indexPath = indexPath

 func didTapCell(index: IndexPath) {
        print("PRESS BUTTON >> \(index.row)")
    }

这篇关于在swift 3中的tableView中按下了哪个单元格按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆