问题
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