實例方法
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 Never sheet(isPresented:onDismiss:content:)用法及代碼示例
- Swift Never shadow(color:radius:x:y:)用法及代碼示例
- Swift Never saturation(_:)用法及代碼示例
- Swift Never simultaneousGesture(_:including:)用法及代碼示例
- Swift Never symbolVariant(_:)用法及代碼示例
- Swift Never scaledToFill()用法及代碼示例
- Swift Never safeAreaInset(edge:alignment:spacing:content:)用法及代碼示例
- Swift Never searchCompletion(_:)用法及代碼示例
- Swift Never submitScope(_:)用法及代碼示例
- Swift Never scaleEffect(x:y:anchor:)用法及代碼示例
- Swift Never speechAlwaysIncludesPunctuation(_:)用法及代碼示例
- Swift Never submitLabel(_:)用法及代碼示例
- Swift Never scaleEffect(_:anchor:)用法及代碼示例
- Swift Never scaledToFit()用法及代碼示例
- Swift Never swipeActions(edge:allowsFullSwipe:content:)用法及代碼示例
- Swift Never suggestedFileName(_:)用法及代碼示例
- Swift Never scenePadding(_:)用法及代碼示例
- Swift Never pageCommand(value:in:step:)用法及代碼示例
- Swift Never opacity(_:)用法及代碼示例
- Swift Never colorMultiply(_:)用法及代碼示例
- Swift Never accessibilityAction(action:label:)用法及代碼示例
- Swift Never alert(isPresented:error:actions:message:)用法及代碼示例
- Swift Never confirmationDialog(_:isPresented:titleVisibility:actions:)用法及代碼示例
- Swift Never flipsForRightToLeftLayoutDirection(_:)用法及代碼示例
- Swift Never position(x:y:)用法及代碼示例
注:本文由純淨天空篩選整理自apple.com大神的英文原創作品 Never sheet(item:onDismiss:content:)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。