I have an action button in UITableViewCell and I would like to detect when the button is pressed and the pressed cell's number from ViewController to make an audio play list in ViewController.swift.
I have been stuck in this problem for a while and I would really appriciate your advice. Here are the codes.
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
}
}
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]***
}
}