首页 > 解决方案 > 将目标添加到单元格但让局部变量迅速产生问题

问题描述

我有一个自定义单元类。我必须在其中添加目标的单元格中有一个按钮。但要这样做,我必须使用 @objc 关键字为操作实现一个函数,而我不能将其作为嵌套函数。是的,由于 indexPath 和单元格等局部变量,我必须创建嵌套函数。谢谢

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "itemCellSub", for: indexPath) as! newInvoicePopup_ItemTableViewCell
        cell.textLabel!.text = (filteredItems[indexPath.row] as! ItemData).name
        cell.detailTextLabel!.text = (filteredItems[indexPath.row] as! ItemData).tax
        cell.priceLabel!.text = (filteredItems[indexPath.row] as! ItemData).price
        cell.addButton.addTarget(self, action: #selector(connected(sender:)), for: .touchUpInside)


        return cell
    }

标签: swiftuitableview

解决方案


推荐阅读