2012-04-02 81 views

回答

0

必须重视目标与你的UIButton。 addTarget方法用于获取事件当你点击按钮,并在UIControl类是直接超类UIButton

- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents 

代码为接收按钮触摸事件定义。

[myButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; 

执行此操作。

-(void) buttonClicked:(id) sender { 
    UIButton* myButton = (UIButton*)sender; 
    //Put your code here 
} 
+0

我感到困惑,我应该补充什么样的代码在我的'UIView',什么在我的'UIViewController' – 2012-04-02 05:16:57

+0

你是在暗示我应该在'UIViewController'创建按钮,然后将其添加到UIView的' ' – 2012-04-02 05:24:08

+1

无论你在'UIView'或'UIViewController'查看它并不重要,但设置“的UIViewController”实例添加按钮为目标,实现'buttonClicked:'在UIViewController类... – Jhaliya 2012-04-02 05:46:36

相关问题