2016-01-13 44 views
0

我不知道这有什么错我code.When我点击该按钮,方法不perform.this是我的代码:蹊跷JSPatch

configView: function() { 
    var button = UIButton.buttonWithType(0); 
    button.setFrame({x:10,y:10,width:100,height:100}); 
    button.setTitle_forState('touch me',0); 
    self.view().addSubView(button); 
    button.setBackgroundColor(UIColor.redColor()); 
    button.setCenter(self.view().center()); 
    button.addTarget_action_forControlEvents(self,'touch',0); 

}, 
touch:function(){ 
    console.log('touchme'); 
} 

难道这是问题? button.addTarget_action_forControlEvents(self,'touch',0)

+0

对不起,在我的代码,'UIButtonTypeCustom UIControlStateNormal'为0这样'VAR键= UIButton.buttonWithType(0); button.setTitle_forState('touch me',0);' – hmxxxhhh

+0

你的评论应该是什么意思? – Davesexcel

+0

@Davesexcel我告诉你的代码是wory,我很抱歉 – hmxxxhhh

回答

0

给Touchupinside的事件,因此它会成功。

[按钮addTarget:自动作:@selector(触摸)forControlEvents:UIControlEventTouchUpInside];

+0

,我试过了,但它需要双击,为什么? – hmxxxhhh

+0

其双击工作? – Romi

+0

button.addTarget_action_forControlEvents(self,'touch',6) – hmxxxhhh

0

我自己了吧,UIControlEventTouchDown类型为NS_OPTIONSUIControlEventTouchDown = 1 << 0,,所以该类型的的intValue是1,我修改我的代码button.addTarget_action_forControlEvents(self,'touch',1),它工作的意愿。