gpt4 book ai didi

ios - SwiftUI 提示 Type of expression is ambiguous without more context in navigationBarItems leading

转载 作者:行者123 更新时间:2023-11-29 11:25:30 25 4
gpt4 key购买 nike

我只是在 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
)
}
}

这就是我想要的 enter image description here

这是我的代码快照: enter image description here

最佳答案

不要相信 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com