如果您在 iOS 上的“文件”应用程序中选择一个文件,您可以点击标题并获得一些额外的操作,类似于上下文菜单。我希望在我的一个应用程序中使用此功能,并了解了
toolbarTitleMenu
修饰符。但是,如果我添加 ShareLink
并点击它,则不会发生任何事情。
这是一个例子:
struct ContentView: View {
var body: some View {
NavigationStack {
Text("Example Content")
.toolbarTitleMenu {
ShareLink(item: "test share content") // Here, nothing happens
}
.navigationTitle("Test Title")
.navigationBarTitleDisplayMode(.inline)
ShareLink(item: "test share content") // Here it works
}
}
}
我做错了什么?
iOS 17.2.1
您缺少
.toolbar
的全部内容。试试这个:
NavigationStack {
Text("Example Content")
.toolbar {
ToolbarTitleMenu {
ShareLink(item: "test share content")
}
}
.navigationTitle("Test Title")
.navigationBarTitleDisplayMode(.inline)
}