實例方法
sheet(item:
sheet(item:onDismiss:content:)
使用給定項目作為工作表內容的數據源呈現工作表。
聲明
func sheet<Item, Content>(
item: Binding<Item?>,
onDismiss: (() -> Void)? = nil,
content: @escaping (Item) -> Content
) -> some View where Item : Identifiable, Content : View
參數
item
綁定到工作表的可選事實來源。當
item
不是nil
時,係統會將項目的內容傳遞給修飾符的閉包。您在係統向用戶顯示的您創建的工作表中顯示此內容。如果item
發生更改,係統將關閉該工作表並使用相同的流程將其替換為新工作表。onDismiss
關閉工作表時要執行的關閉。
content
返回工作表內容的閉包。
詳述
當您需要使用來自自定義數據源的內容呈現模式視圖時,請使用此方法。下麵的示例顯示了一個自定義數據源 InventoryItem
,content
閉包用於填充操作表向用戶顯示的顯示:
struct ShowPartDetail: View {
@State var sheetDetail: InventoryItem?
var body: some View {
Button("Show Part Details") {
sheetDetail = InventoryItem(
id: "0123456789",
partNumber: "Z-1234A",
quantity: 100,
name: "Widget")
}
.sheet(item: $sheetDetail,
onDismiss: didDismiss) { detail in
VStack(alignment: .leading, spacing: 20) {
Text("Part Number: \(detail.partNumber)")
Text("Name: \(detail.name)")
Text("Quantity On-Hand: \(detail.quantity)")
}
.onTapGesture {
sheetDetail = nil
}
}
}
func didDismiss() {
// Handle the dismissing action.
}
}
struct InventoryItem: Identifiable {
var id: String
let partNumber: String
let quantity: Int
let name: String
}
可用版本
iOS 13.0+, iPadOS 13.0+, macOS 10.15+, Mac Catalyst 13.0+, tvOS 13.0+, watchOS 6.0+
相關用法
- Swift Optional sheet(isPresented:onDismiss:content:)用法及代碼示例
- Swift Optional shadow(color:radius:x:y:)用法及代碼示例
- Swift Optional symbolVariant(_:)用法及代碼示例
- Swift Optional saturation(_:)用法及代碼示例
- Swift Optional submitLabel(_:)用法及代碼示例
- Swift Optional speechAlwaysIncludesPunctuation(_:)用法及代碼示例
- Swift Optional submitScope(_:)用法及代碼示例
- Swift Optional scaledToFill()用法及代碼示例
- Swift Optional searchCompletion(_:)用法及代碼示例
- Swift Optional safeAreaInset(edge:alignment:spacing:content:)用法及代碼示例
- Swift Optional simultaneousGesture(_:including:)用法及代碼示例
- Swift Optional scaledToFit()用法及代碼示例
- Swift Optional scenePadding(_:)用法及代碼示例
- Swift Optional scaleEffect(_:anchor:)用法及代碼示例
- Swift Optional scaleEffect(x:y:anchor:)用法及代碼示例
- Swift Optional swipeActions(edge:allowsFullSwipe:content:)用法及代碼示例
- Swift Optional popover(isPresented:attachmentAnchor:arrowEdge:content:)用法及代碼示例
- Swift Optional mask(alignment:_:)用法及代碼示例
- Swift Optional listSectionSeparatorTint(_:edges:)用法及代碼示例
- Swift Optional badge(_:)用法及代碼示例
- Swift Optional fullScreenCover(isPresented:onDismiss:content:)用法及代碼示例
- Swift Optional keyboardType(_:)用法及代碼示例
- Swift Optional clipShape(_:style:)用法及代碼示例
- Swift Optional preferredColorScheme(_:)用法及代碼示例
- Swift Optional background(_:ignoresSafeAreaEdges:)用法及代碼示例
注:本文由純淨天空篩選整理自apple.com大神的英文原創作品 Optional sheet(item:onDismiss:content:)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。