问题
I'm trying to set off a function in my custom tableViewCell-class by using a function in my view controller. I'm really clueless on how to do this, so I tried writing it like this:
TableViewCell.timerStarted()
The function I'm trying to set off looks like this:
func timerStarted(){
timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: "update", userInfo: nil, repeats: true)
}
Where TableViewCell is the name of my class and timerStarted the name of the function. This gives me an error saying it misses an argument inside the parenthesis.
I'm quite stuck here, any suggestions would be appreciated.
回答1:
When you define the function timerStarted
inside your TableViewCell
class, it is an Instance Method. It's should be called on instances of the TableViewCell. To call the function on the class itself, it should have been defined as a type method. To do that, change your definition of timerStarted
by adding class
before it
class func timerStarted(){ ... }
来源:https://stackoverflow.com/questions/27943566/setting-off-a-function-in-another-class