【发布时间】:2021-12-22 18:05:17
【问题描述】:
当用户在Picker 中选择某个选项时,我想设置一个导航标题
这是我的选择模型:
enum AppIcon: CaseIterable, Identifiable {
var id: Self {
return self
}
case `default`
case ethereum
case litecoin
var name: String {
switch self {
case .default:
return "Bitcoin"
case .ethereum:
return "Ethereum"
case .litecoin:
return "Litecoin"
}
}
}
这是我的看法
struct ContentView: View {
@State var icon: AppIcon = .default
var body: some View {
NavigationView {
Form {
Section {
Picker(selection: $icon, label: Text("Icon")) {
ForEach(AppIcon.allCases) { icon in
Text(icon.name).tag(icon)
}
}
}
}
.navigationBarTitle("Appearance")
}
}
}
我想获得这种行为:
但我尝试将.navigationBarTitle("Title") 放在任何右括号之后,但它不起作用。
【问题讨论】: