Ios UIButton操作在swift中不起作用

Ios UIButton操作在swift中不起作用,ios,swift,Ios,Swift,我有两个类UIVIewController和UITableviewcell。在UITableviewcell中,我有一个按钮,按钮操作应该在UIViewController中。如何在按钮操作中传递类和设置委托 我试过这个密码 //UIVIewController cell.createButton(self) func buttonClick(object:AnyObject){ println("Button Clicked") } //UITableViewCell func cr

我有两个类UIVIewController和UITableviewcell。在UITableviewcell中,我有一个按钮,按钮操作应该在UIViewController中。如何在按钮操作中传递类和设置委托

我试过这个密码

//UIVIewController

cell.createButton(self)


func buttonClick(object:AnyObject){
  println("Button Clicked")
}
//UITableViewCell

func createButton(delegate:AnyObject){
//button created.

    button.addTarget(delegate, action: "buttonClick:", forControlEvents: UIControlEvents.TouchUpInside)
}

但上述代码不起作用buttonClick'函数没有调用

我刚才也遇到了同样的问题,试图将self替换为delegate

否则,试着看看这个问题:


我希望能得到帮助。

你们如何以及何时调用createButtondelegate:AnyObject?作为代理传入了什么?我正在CellForRowatineXpath中调用cell.createButtonself。我正在通过一门代表课。好的。谢谢它起作用了。但我想知道,这是正确的做法吗。在目标c中,我认为我们可以传递一个委托并在UITableview单元类中设置目标。为什么不能使用swift?实际上它应该像您编写的代码一样工作,我不知道这是一个bug还是以不同的方式编写的。然而,自我工作: