在另一个类中创build一个函数

我试图通过使用我的视图控制器中的函数在我的自定义tableViewCell类中引发一个函数。 我对如何做到这一点真的很无知,所以我试着写这样的:

TableViewCell.timerStarted() 

我试图摆脱的function看起来像这样:

 func timerStarted(){ timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: "update", userInfo: nil, repeats: true) } 

其中TableViewCell是我的类的名称和timerStarted函数的名称。 这给我一个错误,说它错过了括号内的一个参数。

我很困难,任何build议,将不胜感激。

当您在TableViewCell类中定义函数timerStarted ,它是一个实例方法。 它应该在TableViewCell的实例上调用。 要调用类本身的函数,它应该被定义为一个types方法。 要做到这一点,请在其之前添加class更改timerStarted的定义

 class func timerStarted(){ ... }