私はSegmentedControlを持っています。ユーザーがクリックすると、値を変更するかどうかを確認する確認ダイアログボックスが表示されます。 「キャンセル」をクリックすると、SegmentedControl値の変更を取り消したいと思います。事前に確認ダイアログボックスに基づいてSegmentedControlインデックスが変更されないようにするにはどうすればよいですか?
@IBAction func indexChanged(_ sender: UISegmentedControl) {
let refreshAlert = UIAlertController(title: "Update", message: "Sure you wanna change this?", preferredStyle: UIAlertControllerStyle.alert)
refreshAlert.addAction(UIAlertAction(title: "Ok", style: .default, handler: { (action: UIAlertAction!) in
}))
refreshAlert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (action: UIAlertAction!) in
// Nothing
}))
present(refreshAlert, animated: true, completion: nil)
}
ありがとう:
これは私が持っているコードセグメントです。
しかし、もちろん:
は、以下の完全なコードを参照してください。さらに、 'self.segmentedControl.selectedSegmentIndex = lastSelectedIndex'で直ちに選択したインデックスをリセットするので、KVOオブザーバは2回トリガされ、ユーザが後でOKを選択した場合は3回目にトリガされます。 – Yohst