Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在函数中创建自定义单元格的引用并在Swift中更新标签_Ios_Swift - Fatal编程技术网

Ios 在函数中创建自定义单元格的引用并在Swift中更新标签

Ios 在函数中创建自定义单元格的引用并在Swift中更新标签,ios,swift,Ios,Swift,我一直试图在单击按钮时使用函数中的自定义单元格。并使用函数更新该特定行中的标签 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = myTableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as

我一直试图在单击按钮时使用函数中的自定义单元格。并使用函数更新该特定行中的标签

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

        let cell = myTableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! CardCell

cell.startcount.tag = indexPath.row
                cell.startcount.addTarget(self, action: "startcount:", forControlEvents:UIControlEvents.TouchUpInside)

}
这是我正在使用的函数

func startcount(sender: AnyObject){

// create a reference of  CardCell
// update the counter like cell.textcount.text = "\(counter)"
// in the specific row

    }
我的自定义单元格类:

import UIKit

class CardCell: UITableViewCell {

    @IBOutlet weak var textcount: UILabel!
    @IBOutlet weak var startcount: UIButton!

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}

适用于Swift 4及以上版本

func startCount(sender : AnyObject) {
    let button = sender as! UIButton
    let indexPath = IndexPath(row:button.tag ,section:0)
    let cell = tableView.cellForRow(at: indexPath) as! CardCell
    // update cell
}

适用于Swift 4及以上版本

func startCount(sender : AnyObject) {
    let button = sender as! UIButton
    let indexPath = IndexPath(row:button.tag ,section:0)
    let cell = tableView.cellForRow(at: indexPath) as! CardCell
    // update cell
}