A binding to an optional source of truth for the action sheet.
アクションシートに対するある随意の信頼できる情報源へのあるバインディング。
When item
is non-nil
, the system passes the contents to the modifier’s closure. You use this content to populate the fields of an action sheet that you create that the system displays to the user. If item
changes, the system dismisses the currently displayed action sheet and replaces it with a new one using the same process.
Instance Method
インスタンスメソッド
action
actionSheet(item:content:)
Presents an action sheet using the given item as a data source for the sheet’s content.
アクションシートを提示します、与えられた項目をシートのもつ内容に対するデータソースとして使って。
Availability 有効性
- iOS 13.0–15.4 Deprecated
- iPadOS 13.0–15.4 Deprecated
- Mac Catalyst 13.0–15.4 Deprecated
- tvOS 13.0–15.4 Deprecated
- watchOS 6.0–8.5 Deprecated
Technology
- Swift
UI
Declaration 宣言
func actionSheet<T>(item: Binding
<T?>, content: (T) -> ActionSheet
) -> some View
where T : Identifiable
Parameters パラメータ
item
content
A closure returning the
Action
you create.Sheet
Discussion 議論
Use this method when you need to populate the fields of an action sheet with content from a data source. The example below shows a custom data source, File
, that provides data to populate the action sheet:
struct FileDetails: Identifiable {
var id: String { name }
let name: String
let fileType: UTType
}
struct ConfirmFileImport: View {
var sheetDetail: FileDetails?
var body: some View {
Button("Show Action Sheet") {
sheetDetail = FileDetails(name: "MyImageFile.png",
fileType: .png)
}
.actionSheet(item: $sheetDetail) { detail in
ActionSheet(
title: Text("File Import"),
message: Text("""
Import \(detail.name)?
File Type: \(detail.fileType.description)
"""),
buttons: [
.destructive(Text("Import"),
action: importFile),
.cancel()
])
}
}
func importFile() {
// Handle import action.
}
}