◆OptionButtonsDelegate作成
protocol OptionButtonsDelegate{
func closeFriendsTapped(buttonname: String,at index:Int)
}
◆delegate変数をCustomCellTableViewCellに作成
class CustomCellTableViewCell: UITableViewCell {
var delegate:OptionButtonsDelegate!
@IBAction func btnButtonClick(_ sender: Any) {
self.delegate?.closeFriendsTapped(buttonname:"report",at: (sender as! UIButton).tag)
}
◆ViewControllerでOptionButtonsDelegate を実装
class ViewController: UIViewController,OptionButtonsDelegate{
関数実装
func closeFriendsTapped(buttonname: String,at index: Int) {
print("cell内のButtonがタプされました")
}
◆delegate変数にself設定
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: CustomCellTableViewCell = tableView.dequeueReusableCell(withIdentifier: "mycell", for: indexPath) as! CustomCellTableViewCell
cell.delegate = self