0

カスタム UISwitch を実装する必要があり、そのために RCSwitch クラスを使用しています (Ray Wenderlich と Robert Chin に感謝します)。

そこで、プロジェクトに RCSwitch クラスを追加し、グラフィックを接続しました。うまくいきません。これをチェックしてください:

このコード:

//@interface
@property (nonatomic, strong) RCSwitchOnOff *onSwitch;

//implementation
- (void)viewDidLoad
{
    [super viewDidLoad];

    self.onSwitch = [[RCSwitchOnOff alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2 - 39.5, self.view.frame.size.height/2 - 150, 80, 35)];
    [self.onSwitch addTarget:self action:@selector(switchSwitched:) forControlEvents:UIControlEventTouchUpInside];

//    self.defaultSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2 - 39.5, self.view.frame.size.height/2 - 150, 80, 35)];
//    [self.defaultSwitch addTarget:self action:@selector(switchSwitched:) forControlEvents:UIControlEventTouchUpInside];

.
.
.
}

- (void)switchSwitched:(id)sender
{
    NSLog(@"switch touched!");
}

NSLogでこれを引き起こします

2013-03-15 09:56:54.575 Secret-Project[1190:c07] switch touched!
2013-03-15 09:56:54.576 Secret-Project[1190:c07] switch touched! 

1ユーザー タッチ メソッドの場合、switchSwitched が 2 回起動します。また、defaultSwitch のコメントを外して onSwitch のコメントを付けると、通常の UISwitch は switchSwitched メソッドを 1 回だけ開始します。

一体何?同じ問題を抱えている人はいますか?

4

1 に答える 1