<分区>
我在 UITableViewCell 中有一个操作按钮,我想检测按钮何时被按下以及来自 ViewController 的按下单元格的编号,以便在 ViewController.swift 中制作一个音频播放列表。
我已经被这个问题困住了一段时间,我真的很感激你的建议。这是代码。
ViewController.swift
import UIKit
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
tableView.register(UINib(nibName: "Cell", bundle: nil), forCellReuseIdentifier: "cell")
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 3
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! Cell
return cell
}
}
细胞.swift
import UIKit
class Cell: UITableViewCell {
@IBOutlet weak var button: UIButton!
@IBAction func buttonPressed(_ sender: Any) {
***[Code to send the pressed cell's number to ViewController]***
}
}