2016-01-13 43 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),它工作的意願。