我只是在 navigationBarItems 中放置一些 View ,leading 属性。但是 Xcode 在我的第一个 Text 元素中一直提示“没有更多上下文,表达式类型不明确”:
var body: some View {
NavigationView {
List {
ForEach(people) {person in
PersonView(person: person)
}
}.navigationBarItems(leading: VStack {
HStack(spacing: 100) {
Text("Find People").font(.system(size: 30)).bold()
Text("Follow All").foregroundColor(Color(ColorUtils.hexStringToUIColor(hex: Constants.THEME.THEME_COLOR)))
}
HStack(spacing: 100) {
Text("Import from: ")
ForEach(socialIcons, id: \.self) {icon in
Image(icon).resizable().frame(width: 25, height: 25)
}
}
},
trailing: nil
)
}
}
最佳答案
不要相信 Xcode:
Xcode 是 not very intelligent足以告诉您 SwiftUI 中的真正问题是什么(还)。不管你信不信,问题在于 trailing: nil
。
你应该摆脱它!
那就是:
.navigationBarItems(leading: VStack {
HStack(spacing: 100) {
Text("Find People").font(.system(size: 30)).bold()
Text("Follow All").foregroundColor(Color(ColorUtils.hexStringToUIColor(hex: Constants.THEME.THEME_COLOR)))
}
HStack(spacing: 100) {
Text("Import from: ")
ForEach(socialIcons, id: \.self) {icon in
Image(icon).resizable().frame(width: 25, height: 25)
}
}
}) /* `trailing: nil` removed */
关于ios - SwiftUI 提示 Type of expression is ambiguous without more context in navigationBarItems leading,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59078177/