ios - 将单元委托(delegate)添加到类时出错 - swift

标签 ios swift delegates

当我添加此代码时,为什么会出现错误?: , myProfileWorkoutTableViewCellDelegate

到我的类(class)吗?:

class myProfileTableViewController: UITableViewController, UICollectionViewDataSource, UICollectionViewDelegate, myProfileWorkoutTableViewCellDelegate {

这是我的 myProfileTableViewCell.swift 的开头:

import UIKit
import Firebase
import FirebaseDatabase

protocol myProfileWorkoutTableViewCellDelegate {
    func watchTrainingPressed(cell: myProfileWorkoutTableViewCell)
}

class myProfileWorkoutTableViewCell: UITableViewCell {

这是我在单元格内的按钮:

@IBAction func watchTrainingPressed(sender: AnyObject) {
        if let _ = delegate {
            delegate?.watchTrainingPressed(self)
        }
    }

最佳答案

您需要实现该功能

func watchTrainingPressed(cell: myProfileWorkoutTableViewCell)

在您的 myProfileTableViewController 类中。

关于ios - 将单元委托(delegate)添加到类时出错 - swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40385412/

相关文章:

ios - 单元格中有不必要的填充的 UILabel

ios - 尝试将核心数据对象获取到TableView时出现“NSInvalidArgumentException”

ios - 如何从 gmail api 获取建议/自动完成的电子邮件?

ios - 按钮操作不适用于 subview

ios - 如何区分委托(delegate)方法中的 UITextFields?

ios - NSUserDefaults-插入数组作为对象不起作用

ios - 强制手动关闭 iOS 共享表 Swift iOS 8 和 9

ios - PDFKit后台搜索

ios - 无法在实现中引用委托(delegate)协议(protocol)

c# - 使用具有返回值的多个函数调用委托(delegate)