TVOS: UIButton action not working in subview

六月ゝ 毕业季﹏ 提交于 2019-12-12 04:16:39

问题


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.

Could you help ?


回答1:


Try this.. it worked for me

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


来源:https://stackoverflow.com/questions/33936825/tvos-uibutton-action-not-working-in-subview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!