简体   繁体   English

UIButton动作无法快速运行

[英]UIButton Action not working in swift

I have two classes UIVIewController and UITableviewcell. 我有两个类UIVIewController和UITableviewcell。 In UITableviewcell, i have a button and the button action should be in UIViewController. 在UITableviewcell中,我有一个按钮,该按钮动作应在UIViewController中。 How can i pass a class and set delegate in button action. 我如何通过一个类并在按钮操作中设置委托。

i tried this code, 我尝试了这段代码,

//UIVIewController //的UIViewController

cell.createButton(self)


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

//UITableViewCell //定义UITableViewCell

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

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

But the above code is not working. 但是上面的代码不起作用。 'buttonClick' function is not calling 'buttonClick'函数未调用

I had the same problem a while ago, trying to put self in place of "delegated". 前段时间我遇到了同样的问题,试图将自己置于“委派”的位置。

otherwise try to take a look at this question: 否则尝试看一下这个问题:

link 链接

I hope to be helped. 希望能得到帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM