操作在子视图中不起作用

操作在子视图中不起作用

本文介绍了TVOS:UIButton 操作在子视图中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 TVOS 应用程序故事板主视图中,我添加了一个子视图.在子视图中有 3 个以相同方式创建的按钮(这里的代码属于子视图)

in the TVOS Application storyboard mainview I added a subview.Within the subview there are 3 button created in the very same way (the code here belongs to the subview)

UIButton *b = [UIButton buttonWithType:UIButtonTypeSystem];
b.frame = CGRectMake(left, top,     400, size);
[b setTitle:@"Click Me" forState:UIControlStateNormal];
[b addTarget:self action:@selector(Action_Up) forControlEvents:UIControlEventPrimaryActionTriggered];
[self.view addSubview:b];
...
-(void)Action_Up {
    [self ShowData];
}

在模拟器和真实设备上,我可以选择按钮并按下它,但永远不会触发动作.

in the simulator and on the real device I can select the button and press it, but the action is never fired.

你能帮忙吗?

推荐答案

试试这个.. 对我有用

Try this.. it worked for me

        button.addTarget(self, action: "someMethodName:", forControlEvents: .PrimaryActionTriggered)

这篇关于TVOS:UIButton 操作在子视图中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 08:49