Instance Method インスタンスメソッド

actionSheet(isPresented:content:)

Presents an action sheet when a given condition is true. アクションシートを提示します、与えられた条件がrrueの場合に。

Declaration 宣言

func actionSheet(isPresented: Binding<Bool>, content: () -> ActionSheet) -> some View

Parameters パラメータ

isPresented

A binding to a Boolean value that determines whether to present the action sheet that you create in the modifier’s content closure. When the user presses or taps the sheet’s default action button the system sets this value to false dismissing the sheet.

content

A closure returning the ActionSheet to present. 提示するActionSheetを返しているあるクロージャ。

Discussion 議論

In the example below, a button conditionally presents an action sheet depending upon the value of a bound Boolean variable. When the Boolean value is set to true, the system displays an action sheet with both destructive and default actions:


struct ConfirmEraseItems: View {
    @State private var isShowingSheet = false
    var body: some View {
        Button("Show Action Sheet", action: {
            isShowingSheet = true
        })
        .actionSheet(isPresented: $isShowingSheet) {
            ActionSheet(
                title: Text("Permanently erase the items in the Trash?"),
                message: Text("You can't undo this action."),
                buttons:[
                    .destructive(Text("Empty Trash"),
                                 action: emptyTrashAction),
                    .cancel()
                ]
            )}
    }


    func emptyTrashAction() {
        // Handle empty trash action.
    }
}

An action sheet with a title and message showing the use of default

See Also 参照

View Presentation Modifiers