コードで UITableViewCell に UISwitch を追加し、ターゲット/アクションを追加しました。問題は、UISwitch がタッチされると、反対の値にアニメーション化し始め、購入するとアニメーションが停止し、前の値に戻ることです。つまり、基本的にスライダーはオフからオンに 75% スライドしてからオフに戻るので、切り替えることはできません。切り替えたら、UITableView にセクションを追加しましたが、これが機能しない理由がわかりません。私のコードに何か問題があるかどうか誰かに教えてもらえますか?
UISwitch を追加する場所は次のとおりです。
self.forSaleSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(223.0f, 8.5f, 0.0f, 0.0f)];
[self.forSaleSwitch addTarget:self
action:@selector(switchTapped:)
forControlEvents:UIControlEventValueChanged];
self.forSaleSwitch.backgroundColor = [UIColor clearColor];
self.currentAnnotation.isHouseForSale = (self.forSaleSwitch.on) ? YES : NO;
[cell addSubview:self.forSaleSwitch];
UISwitch のアクションは次のとおりです。
- (void)switchTapped:(id)sender
{
UISwitch *switcher = (UISwitch *)sender;
if (switcher.on)
{
[switcher setOn:NO animated:YES];
self.currentAnnotation.isHouseForSale = NO;
NSLog(@"OFF");
}
else
{
[switcher setOn:YES animated:YES];
self.currentAnnotation.isHouseForSale = YES;
NSLog(@"ON");
}
[self.tableView reloadData];
}