如何以编程方式连接UIButton和方法?

Jam*_*ard 4 objective-c

在我UIView,我有一个UIButton显示.

在同一个UIView类中,我有一个方法,我想按下按钮时执行.

一切都以编程方式完成,而不使用Interface Builder时,如何将两者链接在一起?

Dan*_*Dan 10

使用UIButton addTarget:action:forControlEvents:message指定UIControlEventTouchUpInside事件的选择器.

[myButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
Run Code Online (Sandbox Code Playgroud)