swift - 将目标添加到单元格但让局部变量迅速产生问题
问题描述
我有一个自定义单元类。我必须在其中添加目标的单元格中有一个按钮。但要这样做,我必须使用 @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
}
解决方案
推荐阅读
- php - 如何将 Droplet 与 PhpStorm 连接
- tailwind-css - 变体悬停在 TailwindCss 中不适用
- spring-boot - 未使用 @MapsId 找到父键
- android - 我正在 Glide 中加载图像,但如果 url 包含空格,Glide 将无法工作
- javascript - 简单的 Javascript 幻灯片(所以我知道),获取下一张幻灯片属性以在当前幻灯片中显示
- javascript - 如何在单击输入类型提交后使页面不重新加载并且不打开php页面?
- javascript - async / await 链接何时停止?
- java - XML cardView 阻塞了它下面的 recyclerView 的上半部分
- c# - 如何使用服务帐户发出 Google Home Graph 请求?
- arrays - 使用 fscanf 填充结构体数组