JSPatch

时间:2016-01-13 09:35:48

标签: javascript ios objective-c

我不知道我的代码有什么问题。当我点击按钮时,方法无法执行。这是我的代码:

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)

2 个答案:

答案 0 :(得分:0)

将Touchupinside作为事件,以便它可以正常工作。

[Button addTarget:self action:@selector(touch)forControlEvents:UIControlEventTouchUpInside];

答案 1 :(得分:0)

我自己得到它,UIControlEventTouchDown类型是NS_OPTIONS类型UIControlEventTouchDown = 1 << 0,,所以类型的intValue是1,我修改了我的代码button.addTarget_action_forControlEvents(self,'touch',1),它工作会。

相关问题