【问题标题】:Something wrong with JSPatchJSPatch 出了点问题
【发布时间】:2016-01-13 09:35:48
【问题描述】:

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

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)

【问题讨论】:

  • 对不起,在我的代码中,UIButtonTypeCustom UIControlStateNormal is 0 like this var button = UIButton.buttonWithType(0); button.setTitle_forState('touch me',0);
  • 你的评论是什么意思?
  • @Davesexcel 我给你看的代码很麻烦,对不起

标签: javascript ios objective-c


【解决方案1】:

将 Touchupinside 作为事件提供,以便它可以工作。

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

【讨论】:

  • button.addTarget_action_forControlEvents(self,'touch',6)
  • 怎么给按钮添加方法?
  • 在故事板上你可以给 touchupinside 作为动作,在里面你应该为它写一个函数或动作。例如在上面的编码中 [button add target ....方法是 touch wch 将被调用. @IBAction func settingsButtonClicked() { performSegueWithIdentifier("SettingsPopOverTableViewControllerSegue", sender: self); }
【解决方案2】:

我自己弄的,UIControlEventTouchDown类型是NS_OPTIONStypeUIControlEventTouchDown = 1 << 0,,所以类型的intValue是1,我修改了我的代码button.addTarget_action_forControlEvents(self,'touch',1),就可以了。

【讨论】:

    猜你喜欢
    • 2016-01-01
    • 2011-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-13
    • 1970-01-01
    相关资源
    最近更新 更多