私はゲームを構築しています。UIAlertViewを使用してタッチをキャンセルする
このゲームの設定は&オプション機能のUITableViewController
です。
選択できるオプションの1つは、相手をパスしてAI(またはその逆)に切り替えることです。
私がしたいのは、UIAlertControllerを使用してタッチを傍受し、進行中のゲームをチェックし、変更を取り消したり続行するように促すことです。
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
関数内でこれを行うコードを実装しました。次のように
私のコードは次のとおりです。
if indexPath.section == 1 {
// Here we need to detect a game in progress and ask for a confirmation before switching to another mode.
if getGameInProgress() == true {
// Display choice dialog
alert = UIAlertController (title: alertCaption, message: alertMessage, preferredStyle: .Alert)
let cancelAction: UIAlertAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: {(action: UIAlertAction) -> Void in
self.alert.dismissViewControllerAnimated(true, completion: { _ in })
return
})
alert.addAction(cancelAction)
let ok: UIAlertAction = UIAlertAction(title: "Confirm", style: .Default, handler: {(action: UIAlertAction) -> Void in
self.alert.dismissViewControllerAnimated(true, completion: { _ in })
// Do nothing, just let the touch method continue...
})
alert.addAction(ok)
self.presentViewController (alert, animated: true, completion: nil)
}
if indexPath.row == 0 {
// "Pass and Play"
setOpponentPreference("Pass and Play")
}
if indexPath.row == 1 {
// "Virtual Robert"
setOpponentPreference("Virtual Robert")
}
if indexPath.row == 2 {
// "Virtual Nathan"
setOpponentPreference("Virtual Nathan")
}
// No matter which difficulty selected:
gameboard.setDifficulty()
// Create a method to reset the game, but without fading out the menu screen (the current new game method takes you directly to the game. The player may not want that in this instance.)
}
私が午前問題は、入力のための警告コントローラが表示され、待機していることですが、それは継続didSelectRowAtIndexPath
関数形の残りの部分を防ぐことはできません。
セルのタッチを処理する前に、ユーザー入力を受け取るにはどうすればよいですか?
について。 と、ユーザーがキャンセルボタンを押した場合はどうなりますか? –
@AbdulRehmanWarraich、ユーザーがキャンセルボタンを押した場合、私はdidSelectRowAtIndexPath関数を終了して、コードを追加しないで終了したいと思います。ユーザーが[続行]ボタンを押すと、通常通りにプログラムを続行します。 – zeeple