Iphone 开关按钮在触摸模式下不工作

Iphone 开关按钮在触摸模式下不工作,iphone,objective-c,cocoa-touch,Iphone,Objective C,Cocoa Touch,我不熟悉Objective-C和Cocoa Touch开发。我在一个视图上有一个开/关开关,它应该在同一个视图上禁用/启用隐藏/显示另一个按钮,但由于某些原因,它有时不起作用,这是一种行为: 1st click: Switch to OFF, Other Button hidden => OK 2nd click: Switch to ON, Nothing happens => WRONG 3rd click: Switch to OFF, Other button SHOWN => WRON

我不熟悉Objective-C和Cocoa Touch开发。我在一个视图上有一个开/关开关,它应该在同一个视图上禁用/启用隐藏/显示另一个按钮,但由于某些原因,它有时不起作用,这是一种行为:

1st click: Switch to OFF, Other Button hidden => OK 2nd click: Switch to ON, Nothing happens => WRONG 3rd click: Switch to OFF, Other button SHOWN => WRONG 4th click: Switch to ON, Nothing happens => WRONG 5th click: Switch to OFF, Other Button hidden => OK
我做错了什么?感谢您的帮助。

只要您的
ui开关更改了针对MainViewController的
操作,它就应该可以工作。然而,我建议如下

// Add the (id)sender parameter to obtain the UISwitch (less coupled approach)
-(IBAction)onSwitchChange:(id)sender
{
    // If a control is hidden, disabling it is not required
    resetButton.hidden = ![sender on];
}

谢谢你的帮助!实际上,问题是我使用了“内部润色”操作,我改为“值更改”事件。成功了


非常感谢

尼克有个好建议。但是,您需要找出代码的错误,因为您向我们展示的代码看起来是正确的,但是您看到了错误的行为。即使使用更好的代码,如Nick的代码,您也可能会遇到问题。我怀疑可能-onSwitchChange被多个行动锁定。祝你好运
@synthesize resetButton;

- (IBAction)switchTimer { 
resetButton.enabled = !resetButton.enabled;
resetButton.hidden = !resetButton.hidden;
}
// Add the (id)sender parameter to obtain the UISwitch (less coupled approach)
-(IBAction)onSwitchChange:(id)sender
{
    // If a control is hidden, disabling it is not required
    resetButton.hidden = ![sender on];
}