Skip to content

Instantly share code, notes, and snippets.

@TomoyaOnishi
Last active August 29, 2015 13:56
Show Gist options
  • Save TomoyaOnishi/9152054 to your computer and use it in GitHub Desktop.
Save TomoyaOnishi/9152054 to your computer and use it in GitHub Desktop.
UISwitchのバグ
- (void)viewDidLoad
{
[super viewDidLoad];
// UISwitchのバグ
// スワイプでON・OFFしようとすると
// セットしたセレクタが連続で呼び出される。
UISwitch *hogeSwitch = [[UISwitch alloc] init];
hogeSwitch.center = self.view.center;
[hogeSwitch addTarget:self action:@selector(hogeSwitchDidChangeValue:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:hogeSwitch];
}
- (void)hogeSwitchDidChangeValue:(UISwitch *)hogeSwitch
{
// バグ対応として以前の値と同じ時はreturn
if (self.previousSwitchValue == hogeSwitch.isOn) {
return;
}
}
@TomoyaOnishi
Copy link
Author

UISwitchに対してUIControlEventTouchUpInsideを当てるとイベントが取れないことがあるので、使えない。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment