親ViewControllerの終了をトリガーするオプションの1つを使用して、単純なUIAlertControllerをユーザーに提示したいと思います。これが私が使用しているコードです:
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Close View", style: UIAlertActionStyle.Destructive, handler: {
action in
self.dismissViewControllerAnimated(true, completion: nil)
}))
alert.addAction(UIAlertAction(title: "CANCEL", style: UIAlertActionStyle.Cancel, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
効果はありません。「ビューを閉じる」ハンドラーを実行した後も、アラートを表示するビューコントローラーはまだ存在しています。
self.navigationController?.dismissViewControllerAnimated(true, completion: nil)
UIAlertActionアクションブロックでも試しましたが、それも機能しませんでした。
使用する
self.navigationController?.popViewControllerAnimated(true)
の代わりに
self.dismissViewControllerAnimated(true, completion: nil)
必要に応じて動作し、アラートを表示するViewControllerを閉じます。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加