1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

アラートは最外方につけないとうまく挙動しなかった話

Posted at
        .alert(isPresented: $isShowingAlert) {
            switch viewModel.currentAlertType {
            case .deleteConfirmation:
                return Alert(
                    title: Text("警告"),
                    message: Text("データが削除されますが、よろしいですか?"),
                    primaryButton: .destructive(Text("削除"), action: {
                        if let logID = viewModel.editingLog?.id {
                            DispatchQueue.main.async {
                                navigationManager.path.removeAll()
                                viewModel.editingLog = nil
                            }
                        }
                    }),
                    secondaryButton: .cancel(Text("キャンセル"))
                )
            case .unsavedChanges:
                return Alert(
                    title: Text("警告"),
                    message: Text("内容は保存されませんがよろしいでしょうか?"),
                    primaryButton: .destructive(Text("はい")) {
                        presentationMode.wrappedValue.dismiss()
                    },
                    secondaryButton: .cancel(Text("キャンセル"))
                )
            case .saveFirst:
                return Alert(title: Text("警告"), message: Text("先に釣行記録を保存してください。"), dismissButton: .default(Text("了解")))
            default:
                return Alert(title: Text("エラー"), message: Text("不明なエラーが発生しました。"), dismissButton: .default(Text("了解")))
            }
        }

このようなアラートをSwich文で作りました。というのも一つの画面に複数のアラートがあった場合、SwiftUIでは一つのアラートしか表示されないらしく思ったような実装ができなかったからです。

そしていざ実行、しかしアラートが表示されず、画面をスクロールした瞬間にアラートが表示されるという現象になりました。

##対応

アラートのモディファイアが最外方についていなかったので最外方のVstackに移動した。
これでいけました。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?